iPhone(videostream)でOpenCVを使って6角形を検出しようとしています。私はかなり良い結果を得ていますが、約8 fpsの低いフレームレートのコストで(輪郭の検出に応じて)いくつかのコードスニペットと対応するフレームレート(この呼び出しの後に壊れる場合)に従い、いくつかの時間測定を使用していますOpenCV getTickCount() および getTickFrequency();
clock_t now;
clock_t then;
double tickpersecond = cv::getTickFrequency();
double elapsed_seconds;
// around 24 fps
then = cv::getTickCount();
GaussianBlur( gray, gray, cv::Size(9, 9), 2, 2 ); // 20fps
Canny( gray, gray, m_threshold, m_threshold * 2,3 ); // 13fps
now = cv::getTickCount();
elapsed_seconds = (double)(now - then) / tickpersecond;
// elapsed_seconds is around 0.068183 seconds
//assuming we there are around 120 contours found
cv::findContours( gray, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_TC89_L1, cv::Point(0,0) );
// 10 fps and elapsed_time around 0.008560 seconds
スピードアップするものがあるかどうかはわかりませんが、findContours を実行すると 3 fps 低下するのに、eplapse_time が 0.008560 と非常に低いのは少し奇妙です。ただし、最大の部分は次のコード スニペットです。
for( int i = 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 which I think is not performance relevant
}
//8 fps and elapsed_time == 0.018076
私は10から150までのcontours.size()を扱っています。パフォーマンスを15の一定フレームレートに改善できる点を指摘していただければ幸いです。