0
我正在嘗試一個數字識別。但在輪廓找到後。如圖所示,我在主邊界框內獲得數字0,6,8 ......的邊界框。請幫助我完成圖像處理的第一步。 我曾嘗試使用組矩形,但他們不工作。請檢查下面的代碼。謝謝。刪除數字識別的邊界框內的邊界框
圖片:http://tinypic.com/r/1twx05/5
int main()
{
Mat inimage, gray;
inimage = imread("sample.jpg");
cvtColor(inimage, gray, COLOR_BGR2GRAY);
GaussianBlur(gray, gray, Size(5,5), 0);
adaptiveThreshold(gray, gray, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY_INV, 11, 0);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(gray, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
vector<vector<Point> > contours_poly(contours.size());
vector<Rect> boundRect(contours.size());
for(int i = 0; i < contours.size(); i++)
{
approxPolyDP(Mat(contours[i]), contours_poly[i], 3, true);
boundRect[i] = boundingRect(Mat(contours_poly[i]));
}
//groupRectangles(boundRect, 1, 0.2);
Scalar color = Scalar(0,0,255);
for(int i = 0; i< contours.size(); i++)
{
//drawContours(inimage, contours_poly, i, color, 1, 8, vector<Vec4i>(), 0, Point());
rectangle(inimage, boundRect[i].tl(), boundRect[i].br(), color, 1, 8, 0);
}
namedWindow("Contours", CV_WINDOW_AUTOSIZE);
imshow("Contours", inimage);
waitKey(0);
return 0;
}