how can I find necessary rectangle? or how can I find the width
using the code I can find contour, then draw a rectangle and write information about the width and height.
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
int main(int, char**)
{
VideoCapture cap(0); // open the camera
if(!cap.isOpened()) // check
return -1;
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame;
cvtColor(frame, edges, COLOR_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 50, 3);
vector<vector<Point> > contours;
findContours(edges, contours, RETR_LIST, CHAIN_APPROX_SIMPLE);
for( size_t i = 0; i < contours.size(); i++ )
{
Rect minRect = boundingRect(contours[i]);
if(minRect.width > 50 & minRect.height > 50 )
{
rectangle(frame,minRect,Scalar(0,0,255));
putText(frame,format("width = %d , height = %d",minRect.width,minRect.height), Point(minRect.x,minRect.y),
FONT_HERSHEY_PLAIN, 1, Scalar(0,255,0));
}
}
imshow("frame", frame);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
return 0;
}
With this code I can find required mass for simple figure, how can I as the width of the following figures:
http://www.pictureshack.ru/images/295...
http://www.pictureshack.ru/images/240...
thank you very much
I am not even sure if the provided code has anything to do to the images you are supplying... Is this your own code?
no , Code prompted me to this forum, I'm just trying to use it to solve my problem
You need to stop opening topics about the same problem, open a single one, explain it better and add your image. Then wait for people to help you out.
yes of course, there is still a lot of questions, but unfortunately I can not find a solution, but time is running out - study comes to an end. I published the existing questions in one, but because it did not receive more than one response considered that the question is not clear, so I wanted to write a few simple little question. Sorry
delete or close the question?