[問題] opencv有關SVM hog.detectMultiScale

看板C_and_CPP (C/C++)作者 (Techo)時間11年前 (2014/08/25 14:22), 編輯推噓0(005)
留言5則, 1人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) opencv 問題(Question): 不明原因造成不明matix的size<0 ,導致中斷 餵入的資料(Input): 筆電攝影機 預期的正確結果(Expected Output): 偵測出行人並以矩形框起來 錯誤結果(Wrong Output): OpenCV Error: Assertion failed (s >= 0) in unknown function, file ..\.\opencv\modules\core\src\matrix.cpp, line 115 程式碼(Code):(請善用置底文網頁, 記得排版) #include <iostream> #include <opencv2/opencv.hpp> using namespace std; using namespace cv; int main (int argc, const char * argv[]) { VideoCapture cap(CV_CAP_ANY); cap.set(CV_CAP_PROP_FRAME_WIDTH, 320); cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240); if (!cap.isOpened()) return -1; Mat img; HOGDescriptor hog cout<<detector.size(); hog.setSVMDetector(detector); namedWindow("video capture", CV_WINDOW_AUTOSIZE); while (true) { cap >> img; if (!img.data) continue; vector<Rect> found, found_filtered; →→→→hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2); int a; cin>>a; size_t i, j; for (i=0; i<found.size(); i++) { Rect r = found[i]; for (j=0; j<found.size(); j++) if (j!=i && (r & found[j])==r) break; if (j==found.size()) found_filtered.push_back(r); } for (i=0; i<found_filtered.size(); i++) { Rect r = found_filtered[i]; r.x += cvRound(r.width*0.1); r.width = cvRound(r.width*0.8); r.y += cvRound(r.height*0.06); r.height = cvRound(r.height*0.9); rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 2); } imshow("video capture", img); if (waitKey(20) >= 0) break; } return 0; } 補充說明(Supplement): 不太會加上顏色,箭頭處為程式出問題的中斷點,整個程式主要是setSVMDetector 和detectMultiScale 後面內容為用矩形框出行人處 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.117.247.161 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1408947723.A.A74.html

08/25 14:31, , 1F
08/25 14:31, 1F

08/25 14:33, , 2F
抱歉..這個才是 http://ppt.cc/VDiP
08/25 14:33, 2F

08/26 17:16, , 3F
已找到問題點,opencv本身與VC2012有相容性問題,如果
08/26 17:16, 3F

08/26 17:17, , 4F
使用VC2010可解決,或是在VC2012的屬性→一般→
08/26 17:17, 4F

08/26 17:18, , 5F
平台工具組→設定成"Visual Studio 2010 (v100)"可解決
08/26 17:18, 5F
文章代碼(AID): #1J-jOBfq (C_and_CPP)
文章代碼(AID): #1J-jOBfq (C_and_CPP)