c++ - OpenCV: Speeding up detection of simple shapes on iPhone -
i trying detect shapes 6 corners using opencv on iphone(videostream). getting quite results cost of low frame rate around 8 fps (depending on detecting contours) following code snippets , corresponding frame rate (if break after call) , time measurements using opencv gettickcount() , gettickfrequenzy();
clock_t now; clock_t then; double tickpersecond = cv::gettickfrequency(); double elapsed_seconds; // around 24 fps = cv::gettickcount(); gaussianblur( gray, gray, cv::size(9, 9), 2, 2 ); // 20fps canny( gray, gray, m_threshold, m_threshold * 2,3 ); // 13fps = cv::gettickcount(); elapsed_seconds = (double)(now - then) / tickpersecond; // elapsed_seconds around 0.068183 seconds //assuming there around 120 contours found cv::findcontours( gray, contours, hierarchy, cv_retr_tree, cv_chain_approx_tc89_l1, cv::point(0,0) ); // 10 fps , elapsed_time around 0.008560 seconds
i not sure if there speed find bit strange there drop of 3fps when run findcontours quite low elapsed_time of 0.008560. biggest part following code snippet:
for( int = 0; i< contours.size(); i++ ) { cv::scalar color = cv::scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) ); std::vector<cv::point> output; approxpolydp( contours[i], output, 0.01*arclength(contours[i],true), true ); convexhull( output, convexcontour ); if(conveccontour.size() == 6) //dosomething think not performance relevant } //8 fps , elapsed_time == 0.018076
i dealing contours.size() 10 - 150. hope guys can point out things can improve performance constant frame rate of 15.
problems these flags: cv_retr_tree, cv_chain_approx_tc89_l1
try using: cv_retr_external, cv_chain_approx_simple
your used flags trying find full hierarchy of nested contours.
Comments
Post a Comment