Hi guys. I'm just start OpenCV.
I have some trouble to do my small project.
I want to make a program to detect orange color and draw line from middle to the orange color's average point .
I have a trouble to draw line.
anyone help me??
#include
#include
int main( int argc, char** argv ) {
cv::VideoCapture cap;
if (argc==1) { cap.open(0); // open the default camera }
else { cap.open(argv[1]); }
if( !cap.isOpened() )
{
// check if we succeeded
std::cerr << "Couldn't open capture." << std::endl;
return -1;
}
cv::Mat frame;
while( 1 ) {
cap >> frame;
if( !frame.data ) break; // Ran out of film
cv::Point point_of_poll = Find_poll (freame);
if (point_of_poll.x == 0)
draw_left;
else if (point_of_poll < mid)
draw_left;
else if (point_of_poll > mid)
draw_right;
if( cv::waitKey(33) >= 0 ) break;
}
}
Point Find_poll(Mat frame){
cv::CvSeq* lines = 0;
cv::Mat mask; // specify the range of colours that you want to include, you can play with the borders here
cv::Scalar lowerb = cv::Scalar(38,125,250);
cv::Scalar upperb = cv::Scalar(42,129,255);
cv::inRange(frame, lowerb, upperb, mask); // if the frame has any orange pixel, this will be painted in the mask as white
cv::Mat storage;
cv::Mat result;
lines = cvHoughLines2( mask, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 50, 50, 5 );
cv::Point Averge;
cv::Point Averge.x = 0;
cv::Point Averge.y = 0;
for( i = 0; i < lines->total; i++ )
{
CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
Average.x += line.x;
Average.y += line.y;
}
Average.x = Point_Average.x / lines->total;
Average.y = Point_Average.y / lines->total;
return Average // return averge point of orange poll
}
↧