Recognize Black patterns appearing on the four corners of the image ios using opencv or some other technique

后端 未结 2 965
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 20:06

I am stuck with a problem that is how to recognize some patterns in image.

the image is the image of paper which is pure white and the patterns are in four corners

2条回答
  •  旧时难觅i
    2020-12-01 20:43

    I really don't understand your problem - if you say:

    The image is the image of paper which is pure white and the patterns are in four corners are in black.

    Then what's the problem to mask only these four contours from image? After doing mask with 4 squares with length 40 pixels I got this:

    enter image description here

    To remove small areas you can use morphological operations. I got this:

    enter image description here

    And just draw them (optional) on input image. Here's result:

    enter image description here

    To implement this algorithm I use OpenCV library. I'm 100% sure that it works on IOS - OpenCV team finally published IOS version. So if you say:

    I tried running the OpenCV-iOS link but the project does not run, it is showing errors.

    Then we can't help you with that because we are not telepathists to see your problem. Just small suggestion - try to google your problem. I'm 99% sure that it should help.

    And lest I forget - here's c++ code:

    Mat src = imread("input.png"), tmp;
    
    //convert image to 1bit
    cvtColor(src, tmp, CV_BGR2GRAY);
    threshold(tmp, tmp, 200, 255, THRESH_OTSU);
    
    //do masking
    #define DELTA 40
    for (size_t i=0; i tmp.cols - DELTA)
             || (i > tmp.rows - DELTA && j < DELTA)
             || (i > tmp.rows - DELTA && j > tmp.cols - DELTA)))
            {
                //set color to black
                tmp.at(i, j) = 255;
            }
        }
    }
    
    bitwise_not(tmp,tmp);
    
    //erosion and dilatation:
    Mat element = getStructuringElement(MORPH_RECT, Size(2, 2), Point(1, 1));
    
    erode(tmp, tmp, element);
    dilate(tmp, tmp, element);
    
    //(Optional) find contours and draw them:
    vector hierarchy;
    vector > contours;
    
    findContours(tmp, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
    
    for (size_t i=0; i

提交回复
热议问题