Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

How con a find a specif point through a contour?

$
0
0
Hey, guys. I've been working on a project lately, I'm trying to create a line follower robot using the raspberry pi and it's camera module. I'm really new to opencv and I've been struggling to actually solve a problem I'm having. I'm able to track the black line that is placed over a white floor, using this [tutorial](https://www.youtube.com/watch?v=bSeFrPrqZ2A&t=6s). I was using it to track the center point of the line and it was working quite nicely, but I've recently found a problem with this aproach. It only works in straight lines, not in angled ones. So I have to chage it. In order to solve my issue, I tought I could track the two boundaries of the line (left side and right side), in the midle of the screen. The frame height is 480px, so I tought it'd points in the contour vector with y=240 and I tried to check this vector to find the x coordinates of said points. It works sometimes, but I can't find it consistently, as can be seen in this [video](https://www.youtube.com/watch?v=4cjksm14Uqs). This is the code I'm using to track the line: double trackFilteredObject(int &x, int &y, Mat threshold, Mat &cameraFeed){ double distanceleft, distanceright, diference; Mat temp; //Rect bounding; double dist; Point teste; threshold.copyTo(temp); int contornox=0, contornoy=0, contornox2 = 0, contornoy2 = 0; vector< vector> contours; vector hierarchy; findContours(temp, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE); double refArea = 0; bool objectFound = false; //drawContours(temp,contours,0,Scalar(0,255,0),1,8,hierarchy); if(hierarchy.size() > 0){ int numOjbects = hierarchy.size(); if(numOjbects =0; index = hierarchy[index][0]){ Moments moment = moments((Mat)contours[index]); double area = moment.m00; if(area>MIN_OBJECT_AREA && arearefArea){ x = moment.m10/area; y = moment.m01/area; objectFound = true; refArea = area; for (int i=0; i< contours[0].size(); i++){ Point coordinate_i_ofcontour = contours[0][i]; //usleep(2000000); // cout<

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>