c++ - Speeding up processing speed for HoughCircles -
i working on hough circles function. when use function, processing speed quite slow. example, real time video feeding have lags of 1 seconds when move camera. or 10 seconds. code follows
#include <sstream> #include <string> #include <iostream> #include <vector> #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <opencv\cv.h> #include <opencv\highgui.h> #include <stdlib.h> #include <stdio.h> using namespace std; using namespace cv; int main(int argc, char** argv) { //create window trackbars namedwindow("trackbar window", cv_window_autosize); //create trackbar change brightness int islidervalue1 = 50; createtrackbar("brightness", "trackbar window", &islidervalue1, 100); //create trackbar change contrast int islidervalue2 = 50; createtrackbar("contrast", "trackbar window", &islidervalue2, 100); //create trackbar change param1 in houghcircle int param1 = 150; createtrackbar("param1", "trackbar window", ¶m1, 300); //create trackbar change param2 in houghcircle int param2 = 200; createtrackbar("param2", "trackbar window", ¶m2, 300); //create trackbar change min radius in houghcircle int minr = 0; createtrackbar("minradius", "trackbar window", &minr, 300); //create trackbar change max radius in houghcircle int maxr = 0; createtrackbar("maxradius", "trackbar window", &maxr, 300); //debugging purpose cout << "all trackbars created" << endl; //create variable store image mat src; //create video capture videocapture capture; //open video either file or webcam //capture.open("c:\\users\\student-id\\downloads\\space mission iiia\\gopr0503.mp4"); capture.open(0); //store whatever captured src capture.read(src); //set frame height capture.set(cv_cap_prop_frame_height, 240); capture.set(cv_cap_prop_frame_width, 320); //debugging purpose cout << "vidoe opened" << endl; if (!src.data) { std::cout << "error:\topening image" << std::endl; return -1; } //create window display videos cv::namedwindow("image1", cv_window_autosize); while (true){ capture.read(src); //code changing brightness , contrast int ibrightness = islidervalue1 - 50; double dcontrast = islidervalue2 / 50.0; src.convertto(src, -1, dcontrast, ibrightness); //debugging purpose cout << "1" << endl; //create variable store processed image mat src_gray2; //convert colour grayscale cvtcolor(src, src_gray2, cv_bgr2gray); //smooth , blur image reduce noise gaussianblur(src_gray2, src_gray2, cv::size(9, 9), 2, 2); vector<vec3f> circles; //change param1 , 2 double integer double dparam1 = param1 / 1.0; double dparam2 = param2 / 1.0; //debugging purpose cout << "2" << endl; //apply houghcircle function houghcircles(src_gray2, circles, cv_hough_gradient, 2, // accumulator resolution (size of image / 2) 5, // minimum distance between 2 circles dparam1, // canny high threshold dparam2, // minimum number of votes minr, maxr); // min , max radius //debugging purpose cout << "3" << endl; //draw circle (size_t = 0; < circles.size(); i++) { point center(cvround(circles[i][0]), cvround(circles[i][1])); int radius = cvround(circles[i][2]); circle(src, center, 3, scalar(0, 255, 0), -1, 8, 0); // circle outline circle(src, center, radius, scalar(0, 0, 255), 3, 8, 0); //display words on top left hand corner puttext(src, "circle found", point(0, 50), 1,2,scalar(0, 255, 0),2); } //display video imshow("image1", src); //debugging purpose cout << "5" << endl; //delay refresh pic cvwaitkey(33); } return 0; }
so debugging numbering stops @ "2" 10 seconds before jump 3. told before increase param1 , param2, if max both 300 or 200, no circles detected. note: circles of various sizes, can forget min , max radius
this amount of lag me, there way improve speed of processing respect coding , others?
i using opencv 3.0.0 c++ on microsoft visual studio 2013, running win 8 64bit system.
Comments
Post a Comment