Robust card detection/persecutive correction OpenCV

前端 未结 2 1587
孤独总比滥情好
孤独总比滥情好 2021-01-30 19:11

I currently have a method for detecting a card in an image and for the most part it works when the lighting is fairly consistent and the background is very calm.

Here is

2条回答
  •  孤街浪徒
    2021-01-30 19:49

    A more general approach would definitely be something like Rutger Nijlunsing suggested in his answer. However, in your case, at least for the provided sample images, a very simple approach like morphological opening followed by thresholding, contour processing and convexhull would yield the result you want. Use a scaled down version of the images for processing so that you don't have to use a large kernel for morphological operations. Below are the images processed this way.

        pyrDown(large, rgb0);
        pyrDown(rgb0, rgb0);
        pyrDown(rgb0, rgb0);
    
        Mat small;
        cvtColor(rgb0, small, CV_BGR2GRAY);
    
        Mat morph;
        Mat kernel = getStructuringElement(MORPH_ELLIPSE, Size(11, 11));
        morphologyEx(small, morph, MORPH_OPEN, kernel);
    
        Mat bw;
        threshold(morph, bw, 0, 255.0, CV_THRESH_BINARY | CV_THRESH_OTSU);
    
        Mat bdry;
        kernel = getStructuringElement(MORPH_ELLIPSE, Size(3, 3));
        erode(bw, bdry, kernel);
        subtract(bw, bdry, bdry);
    
        // do contour processing on bdry
    

    This approach will not work in general, so I would strongly recommend something like Rutger suggested.

    enter image description here

    enter image description here

    enter image description here

提交回复
热议问题