0

I have a small chessboard and I put a geometric objects in the white squares, now I'm trying to extract them from the image using cv::findContours(), here my code and the source and result images:

int main (){
    cv::Mat img = cv::imread("quad.jpg",0);
    cv::Mat image ;
    cv::Mat result(img.size(),CV_8U,cv::Scalar(255));
    std::vector<std::vector<cv::Point>> contours;
    //std::vector<std::vector<cv::Point2f>> hiararchy;
    cv::threshold(img,img,127,255,CV_THRESH_BINARY_INV);
    cv::findContours(img,contours,/*hiararchy,*/CV_RETR_TREE    , CV_CHAIN_APPROX_NONE );
-1, // draw all contours
cv::Scalar(0), // in black
2); // with a thickness of 2
    cv::imshow("result",result);
    //cv::imwrite("con.jpg",result);
    cv::waitKey(0);

    return 0;

source

source

result

result

any idea how to tell the program : care only about the white squares

thanks!

4

1 回答 1

1

使用霍夫变换找到图像中最长的线。这将为您提供棋盘格。接下来,您可以检查网格上每个“单元”内的平均像素颜色,以确定它是黑色方块还是白色方块。

于 2013-07-18T09:46:09.330 回答