c++ - Calculate the distance to a red point with opencv -
i'm newbie opencv. managed install , set visual 2013. tested sample of live stream laptop's camera , works. want calculate distance webcam red laser spot in middle of screen(live_stream). tell me can start? know must find r(red) pixel middle of screen dont know how , functions can use. help, please? live stream webcam works shown below:
#include "opencv2/highgui/highgui.hpp" #include <opencv2/objdetect/objdetect.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <iostream> #include <vector> #include <stdio.h> int main() { //data structure store cam. cvcapture* cap=cvcreatecameracapture(0); //image variable store frame iplimage* frame; //window show livefeed cvnamedwindow("imagine live",cv_window_autosize); while(1) { //load next frame frame=cvqueryframe(cap); //if frame not loaded break loop if(!frame) printf("\nno");; //show present frame cvshowimage("imagine live",frame); //escape sequence char c=cvwaitkey(33); //if key pressed user esc(ascii 27) break out of loop if(c==27) break; } //cleanup cvreleasecapture(&cap); cvdestroyallwindows(); }
your red dot going show total white in camera stream, suggest
- convert grayscale using
cvtcolor(). - threshold using
threshold(), parameters use thresh=253, maxval=255 , mode thresh_binary. should give image black small white dot laser is. - then can use
findcontours()locate dot in image.boundingrect()of contour , can calculate center precise coordinates of dot.
also has been mentioned, not use deprecated c api, use c++ api instead.
Comments
Post a Comment