void main() { int i=0; String cn="haarcascade_frontalface_alt.xml"; CascadeClassifier cd; vector<Rect> faces; bool cb=cd.load(cn); Point cent; bool lock=true; int nodetect_cnt=0; int clickdetectcnt=3; bool quit=false; try { VideoCapture cap(-1); cap.set(CV_CAP_PROP_FRAME_WIDTH,320); cap.set(CV_CAP_PROP_FRAME_HEIGHT,240); if(!cap.isOpened()) { std::cout<<"not found"; } else{ voce::init("./lib", false, true, "./grammar", "digits"); std::cout<<"yeah"; } std::cout<<cap.get(CV_CAP_PROP_FRAME_HEIGHT)<<"_________________"<<cap.get(CV_CAP_PROP_FRAME_WIDTH)<<std::endl; for(;;) { //std::cout<<"yahan aaya "; Mat frame; rectval r1=sens(); cap >> frame; ellipse( frame, frame_center(), Size(5,5), 0, 0, 360, Scalar( 255, 0, 255 ), 2, 8, 0 ); rectangle(frame,Point(r1.x,r1.y),Point(r1.x+r1.width,r1.y+r1.height),Scalar( 255, 0, 255 )); cd.detectMultiScale(frame,faces); for(int i=0 ; i<faces.size();i++){ Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 ); cent=center; if(lock==true) convert(center); ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 2, 8, 0 ); ellipse( frame, center, Size( 5, 5), 0, 0, 360, Scalar( 50, 205, 50 ), 2, 8, 0 ); } imshow("edges", frame); int c=waitKey(20); if (voce::getRecognizerQueueSize() > 0) { std::string s = voce::popRecognizedString(); if (std::string::npos != s.rfind("stop")) { quit = true; break; } std::string aopen="click",areset="center",apause="pause",aresume="resume",adblclick="double"; if(aopen.compare(s)==0){ sendEvent(1); } if(areset.compare(s)==0) setCenter(cent.x,cent.y); if(apause.compare(s)==0) lock=false; if(aresume.compare(s)==0) lock=true; if(adblclick.compare(s)==0) sendEvent(2); std::cout << "You said: " << s << std::endl; //voce::synthesize(s); } //if(c==99) if(c==27) break; if(c==108) lock=false; if(c==107) lock=true; //cout<<c; } voce::destroy(); } catch( cv::Exception& e ) { std::cout<< "---------"<<e.what(); } //int a; //std::cin>>a; }
std::vector<cv::Vec3f> CircularSampleAreaDetector::detect(cv::Mat frame) { // Convert the image to grayscale cv::Mat frame_gray(frame); cv::cvtColor(frame, frame_gray, CV_BGR2GRAY); // cv::cvtColor(frame, frame_gray, CV_BGR2HSV); // std::vector<cv::Mat> channels; // cv::split(frame_gray, channels); // frame_gray = channels[2]; // Blur to remove extraneous detail before edge detection // cv::medianBlur(frame_gray, frame_gray, 9); // cv::blur(frame_gray, frame_gray, cv::Size(3, 3)); cv::GaussianBlur(frame_gray, frame_gray, cv::Size(9, 9), 2, 2); // cv::imshow("blur_win", frame_gray); // Edge detection // cv::adaptiveThreshold(frame_gray, frame_gray, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 11, 1); cv::Mat frame_canny; // int erosion_size = 2; // cv::Mat element = getStructuringElement(cv::MORPH_ELLIPSE, // cv::Size( 2*erosion_size + 1, 2*erosion_size+1), // cv::Point( erosion_size, erosion_size )); // cv::dilate(frame_gray, frame_gray, element ); // cv::erode(frame_gray, frame_gray, element ); // cv::Canny(frame_gray, frame_canny, 5, 50); // cv::imshow("canny_win", frame_canny); // Extract circle features std::vector<cv::Vec3f> circles; // HoughCircles(frame_gray, circles, CV_HOUGH_GRADIENT, 1, 50, 50, 40, 0, 0); HoughCircles(frame_gray, circles, CV_HOUGH_GRADIENT, 2, // inverse resolution ratio 50, // min dist between circle centers 50, // canny upper threshold 150, // center detection threshold 0, // min radius 0 // max radius ); // HoughCircles(frame_gray, circles, CV_HOUGH_GRADIENT, // 1, // inverse resolution ratio // 50, // min dist between circle centers // 50, // canny upper threshold // 50, // center detection threshold // 0, // min radius // 0 // max radius // ); // Of the circles found, pick the one closest to the center of the frame // TODO: This is not the best way to do this. Research probabilistic methods? cv::Point frame_center(frame_gray.cols / 2, frame_gray.rows / 2); std::vector<cv::Vec3f> good_circles; for(size_t i = 0; i < circles.size(); i++) { cv::Point center(cvRound(circles[i][0]), cvRound(circles[i][1])); int radius = circles[i][2]; // Ensure circle is entirely in screen if(center.x - radius < 0 || center.x + radius > frame_gray.cols || center.y - radius < 0 || center.y + radius > frame_gray.rows) { continue; } good_circles.push_back(cv::Vec3f(circles[i][0], circles[i][1], circles[i][2] * CIRCLE_SHRINK_FACTOR)); } return good_circles; }