Opencv crop part of image in outline

enter image description here

I just started learning OpenCv. I wanted to crop a portion of the image, which is text surrounded by a red circle. can you guys help me find a solution, like all the methods that i have to follow to crop it. I tried a few things and cut the red circle and kept it in the rug.

while(1) { capture>>img0; imshow("original", img0); imwrite("original.jpg", img0); cv::inRange(img0,cv::Scalar(0,0,100),cv::Scalar(76,85,255),img1); imshow("threshold.jpg", img1); imwrite("threshold.jpg", img1); // find the contours vector< vector<Point> > contours; findContours(img1, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); Mat mask = Mat::zeros(img1.rows, img1.cols, CV_8UC1); drawContours(mask, contours, -1, Scalar(255), CV_FILLED); Mat crop(img0.rows, img0.cols, CV_8UC3); crop.setTo(Scalar(255,255,255)); img0.copyTo(crop, mask); normalize(mask.clone(), mask, 0.0, 255.0, CV_MINMAX, CV_8UC3); imshow("mask", mask); imshow("cropped", crop); imwrite("mask.jpg", mask); imwrite("cropped.jpg", crop); if(waitKey(30)=='27') { break; } } return 0;`[original image[cropped image][1]` 

From this image, I wanted to crop the text alone. help me find a solution by sharing me with methods or steps.

Thank you in advance

+6
source share
1 answer

If you want to extract the text yourself, you can try the following: -

 drawContours(mask, contours, -1, Scalar(255), CV_FILLED); vector<Rect> boundRect( contours.size() ); for(int i=0;i<contours.size();i++) { boundRect[i] = boundingRect(contours[i]);//enclose in Rect Mat ROI,ROI_txt; if(boundRect[i].width>30 && boundRect[i].height>30)//ignore noise rects { ROI=img0(boundRect[i]);//extract Red circle on ROI inRange(ROI,Scalar(0,0,0),cv::Scalar(50,50,50),ROI_txt); //black colour threshold to extract black text } } 
+2
source

All Articles