[问题] opencv有关SVM hog.detectMultiScale

楼主: techo0116 (Techo)   2014-08-25 14:22:01
开发平台(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 后面内容为用矩形框出行人处
楼主: techo0116 (Techo)   2014-08-25 14:31:00
附上参考网址http://www.magicandlove.com/blog/2011/0抱歉..这个才是 http://ppt.cc/VDiP

Links booklink

Contact Us: admin [ a t ] ucptt.com