質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Q&A

解決済

1回答

864閲覧

笑顔算出場所と方法について

kotetu

総合スコア34

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

0グッド

0クリップ

投稿2018/02/09 04:50

閲覧ありがとうございます。

笑顔検出を使って、何か面白い事が出来ないかと模索中です。

自分自身でも追ってますが、よく分からなくなってしまったので質問させて頂きました。
以下に、自分が使っている笑顔検出のオープンソースを載せておきます。
OpenCVの笑顔検出オープンソース

Ⅰ.rect_heightは、img.rowとintensityZeroOneを使って出されている。
Ⅱ.intensityZeroOneは、smile_neighborsとmin_neignborsとmax_neighbors
を使って出されている。
Ⅲ.smile_neighborsは、nestedObject.size()を使って出されている。
Ⅳ.nestedObject.size()は、 nestedCascade.detectMultiScaleを使って出されている。

このⅠからⅣであってますでしょうか?間違ってたらすみません。

今、detectMultiScaleの事について調べているのですが、ここがよく分かっていない所です。

後、実行の際の横のバーを出すための、最終的な理屈が分かっていません。

お願い致します。

C++

1#include "opencv2/objdetect.hpp" 2#include "opencv2/highgui.hpp" 3#include "opencv2/imgproc.hpp" 4#include <iostream> 5 6using namespace std; 7using namespace cv; 8 9static void help() 10{ 11 cout << "\nThis program demonstrates the smile detector.\n" 12 "Usage:\n" 13 "./smiledetect [--cascade=<cascade_path> this is the frontal face classifier]\n" 14 " [--smile-cascade=[<smile_cascade_path>]]\n" 15 " [--scale=<image scale greater or equal to 1, try 2.0 for example. The larger the faster the processing>]\n" 16 " [--try-flip]\n" 17 " [video_filename|camera_index]\n\n" 18 "Example:\n" 19 "./smiledetect --cascade=\"../../data/haarcascades/haarcascade_frontalface_alt.xml\" --smile-cascade=\"../../data/haarcascades/haarcascade_smile.xml\" --scale=2.0\n\n" 20 "During execution:\n\tHit any key to quit.\n" 21 "\tUsing OpenCV version " << CV_VERSION << "\n" << endl; 22} 23 24void detectAndDraw( Mat& img, CascadeClassifier& cascade, 25 CascadeClassifier& nestedCascade, 26 double scale, bool tryflip ); 27 28string cascadeName; 29string nestedCascadeName; 30 31int main( int argc, const char** argv ) 32{ 33 VideoCapture capture; 34 Mat frame, image; 35 string inputName; 36 bool tryflip; 37 38 help(); 39 40 CascadeClassifier cascade, nestedCascade; 41 double scale; 42 cv::CommandLineParser parser(argc, argv, 43 "{help h||}{scale|1|}" 44 "{cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|}" 45 "{smile-cascade|../../data/haarcascades/haarcascade_smile.xml|}" 46 "{try-flip||}{@input||}"); 47 if (parser.has("help")) 48 { 49 help(); 50 return 0; 51 } 52 cascadeName = parser.get<string>("cascade"); 53 nestedCascadeName = parser.get<string>("smile-cascade"); 54 tryflip = parser.has("try-flip"); 55 inputName = parser.get<string>("@input"); 56 scale = parser.get<int>("scale"); 57 if (!parser.check()) 58 { 59 help(); 60 return 1; 61 } 62 if (scale < 1) 63 scale = 1; 64 if( !cascade.load( cascadeName ) ) 65 { 66 cerr << "ERROR: Could not load face cascade" << endl; 67 help(); 68 return -1; 69 } 70 if( !nestedCascade.load( nestedCascadeName ) ) 71 { 72 cerr << "ERROR: Could not load smile cascade" << endl; 73 help(); 74 return -1; 75 } 76 if( inputName.empty() || (isdigit(inputName[0]) && inputName.size() == 1) ) 77 { 78 int c = inputName.empty() ? 0 : inputName[0] - '0' ; 79 if(!capture.open(c)) 80 cout << "Capture from camera #" << c << " didn't work" << endl; 81 } 82 else if( inputName.size() ) 83 { 84 if(!capture.open( inputName )) 85 cout << "Could not read " << inputName << endl; 86 } 87 88 if( capture.isOpened() ) 89 { 90 cout << "Video capturing has been started ..." << endl; 91 cout << endl << "NOTE: Smile intensity will only be valid after a first smile has been detected" << endl; 92 93 for(;;) 94 { 95 capture >> frame; 96 if( frame.empty() ) 97 break; 98 99 Mat frame1 = frame.clone(); 100 detectAndDraw( frame1, cascade, nestedCascade, scale, tryflip ); 101 102 char c = (char)waitKey(10); 103 if( c == 27 || c == 'q' || c == 'Q' ) 104 break; 105 } 106 } 107 else 108 { 109 cerr << "ERROR: Could not initiate capture" << endl; 110 help(); 111 return -1; 112 } 113 114 return 0; 115} 116 117void detectAndDraw( Mat& img, CascadeClassifier& cascade, 118 CascadeClassifier& nestedCascade, 119 double scale, bool tryflip) 120{ 121 vector<Rect> faces, faces2; 122 const static Scalar colors[] = 123 { 124 Scalar(255,0,0), 125 Scalar(255,128,0), 126 Scalar(255,255,0), 127 Scalar(0,255,0), 128 Scalar(0,128,255), 129 Scalar(0,255,255), 130 Scalar(0,0,255), 131 Scalar(255,0,255) 132 }; 133 Mat gray, smallImg; 134 135 cvtColor( img, gray, COLOR_BGR2GRAY ); 136 137 double fx = 1 / scale; 138 resize( gray, smallImg, Size(), fx, fx, INTER_LINEAR_EXACT ); 139 equalizeHist( smallImg, smallImg ); 140 141 cascade.detectMultiScale( smallImg, faces, 142 1.1, 2, 0 143 //|CASCADE_FIND_BIGGEST_OBJECT 144 //|CASCADE_DO_ROUGH_SEARCH 145 |CASCADE_SCALE_IMAGE, 146 Size(30, 30) ); 147 if( tryflip ) 148 { 149 flip(smallImg, smallImg, 1); 150 cascade.detectMultiScale( smallImg, faces2, 151 1.1, 2, 0 152 //|CASCADE_FIND_BIGGEST_OBJECT 153 //|CASCADE_DO_ROUGH_SEARCH 154 |CASCADE_SCALE_IMAGE, 155 Size(30, 30) ); 156 for( vector<Rect>::const_iterator r = faces2.begin(); r != faces2.end(); ++r ) 157 { 158 faces.push_back(Rect(smallImg.cols - r->x - r->width, r->y, r->width, r->height)); 159 } 160 } 161 162 for ( size_t i = 0; i < faces.size(); i++ ) 163 { 164 Rect r = faces[i]; 165 Mat smallImgROI; 166 vector<Rect> nestedObjects; 167 Point center; 168 Scalar color = colors[i%8]; 169 int radius; 170 171 double aspect_ratio = (double)r.width/r.height; 172 if( 0.75 < aspect_ratio && aspect_ratio < 1.3 ) 173 { 174 center.x = cvRound((r.x + r.width*0.5)*scale); 175 center.y = cvRound((r.y + r.height*0.5)*scale); 176 radius = cvRound((r.width + r.height)*0.25*scale); 177 circle( img, center, radius, color, 3, 8, 0 ); 178 } 179 else 180 rectangle( img, cvPoint(cvRound(r.x*scale), cvRound(r.y*scale)), 181 cvPoint(cvRound((r.x + r.width-1)*scale), cvRound((r.y + r.height-1)*scale)), 182 color, 3, 8, 0); 183 184 const int half_height=cvRound((float)r.height/2); 185 r.y=r.y + half_height; 186 r.height = half_height-1; 187 smallImgROI = smallImg( r ); 188 nestedCascade.detectMultiScale( smallImgROI, nestedObjects, 189 1.1, 0, 0 190 //|CASCADE_FIND_BIGGEST_OBJECT 191 //|CASCADE_DO_ROUGH_SEARCH 192 //|CASCADE_DO_CANNY_PRUNING 193 |CASCADE_SCALE_IMAGE, 194 Size(30, 30) ); 195 196 // The number of detected neighbors depends on image size (and also illumination, etc.). The 197 // following steps use a floating minimum and maximum of neighbors. Intensity thus estimated will be 198 //accurate only after a first smile has been displayed by the user. 199 const int smile_neighbors = (int)nestedObjects.size(); 200 static int max_neighbors=-1; 201 static int min_neighbors=-1; 202 if (min_neighbors == -1) min_neighbors = smile_neighbors; 203 max_neighbors = MAX(max_neighbors, smile_neighbors); 204 205 // Draw rectangle on the left side of the image reflecting smile intensity 206 float intensityZeroOne = ((float)smile_neighbors - min_neighbors) / (max_neighbors - min_neighbors + 1); 207 int rect_height = cvRound((float)img.rows * intensityZeroOne); 208 Scalar col = Scalar((float)255 * intensityZeroOne, 0, 0); 209 rectangle(img, cvPoint(0, img.rows), cvPoint(img.cols/10, img.rows - rect_height), col, -1); 210 } 211 212 imshow( "result", img ); 213}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

このⅠからⅣであってますでしょうか?間違ってたらすみません。

はい

後、実行の際の横のバーを出すための、最終的な方法が分かっていません。

cv::rectangleimgにバーを書き込んでcv::imshowで表示ですね。

投稿2018/02/09 16:57

yumetodo

総合スコア5850

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問