C++ HOGDescriptor OpenCV dsize.area()断言失败
我正在尝试训练SVM,并在OpenCV的HOGDescrpitor中使用它 xml文件已由HOGDescriptor成功生成并加载,但当我尝试检测某个对象时,发生了断言: OpenCV错误:断言失败(dsize.area()| |(inv_scale_x>0&& inv_scale_y>0)在调整大小、文件中 /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/imgwarp.cpp,第行 1825在抛出的实例后调用terminate 'tbb::捕获的\u异常'what(): /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/imgwarp.cpp:1825: 错误:(-215)dsize.area()| |(inv_scale_x>0和&inv_scale_y>0)位于 函数调整大小 为了实现SVM训练器,我使用了 生成的XML文件大约有144KB。对于正片和负片样本,我使用了64x128大小的图像(正片为2000,负片为2000) SVM训练器的参数:C++ HOGDescriptor OpenCV dsize.area()断言失败,c++,opencv,detection,C++,Opencv,Detection,我正在尝试训练SVM,并在OpenCV的HOGDescrpitor中使用它 xml文件已由HOGDescriptor成功生成并加载,但当我尝试检测某个对象时,发生了断言: OpenCV错误:断言失败(dsize.area()| |(inv_scale_x>0&& inv_scale_y>0)在调整大小、文件中 /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/imgwarp.cpp,第行 1825在抛出的实例后调用terminate 'tb
CvSVMParams svmParams;
svmParams.svm_type = CvSVM::C_SVC;
svmParams.kernel_type = CvSVM::LINEAR;
svmParams.term_crit = cvTermCriteria( CV_TERMCRIT_ITER, 10000, 1e-6 );
检测代码:
int main()
{
HOGDescriptor hog();
if(!hog.load("/home/bin/hogdescriptor.xml"))
{
std::cout << "Failed to load file!" << std::endl;
return -1;
}
VideoCapture cap(0);
if(!cap.isOpened())
{
std::cout << "Error opening camera!" << std::endl;
return 1;
}
Mat testImage;
while ((cvWaitKey(30) & 255) != 27)
{
cap >> testImage;
detectTest(hog, testImage);
imshow("HOG custom detection", testImage);
}
return EXIT_SUCCESS;
}
void showDetections(const vector<Rect>& found, Mat& imageData) {
for (const Rect& rect : found)
{
Point rectPoint1;
rectPoint1.x = rect.x;
rectPoint1.y = rect.y;
Point rectPoint2;
rectPoint2.x = rect.x + rect.width;
rectPoint2.y = rect.y + rect.height;
std::cout << "detection x: " << rect.x << ", y: " << rect.y << std::endl;
rectangle(imageData, rectPoint1, rectPoint2, Scalar(0, 255, 0));
}
}
void detectTest(const HOGDescriptor& hog, Mat& imageData)
{
std::cout << "Trying to detect" << std::endl;
vector<Rect> found;
int groupThreshold = 2;
Size padding(Size(32, 32));
Size winStride(Size(8, 8));
double hitThreshold = 0.; // tolerance
hog.detectMultiScale(imageData, found, hitThreshold, winStride, padding, 1.05, groupThreshold);
// hog.detectMultiScale(imageData, found);
std::cout << "Trying to show detections" << std::endl;
showDetections(found, imageData);
}
intmain()
{
hog();
如果(!hog.load(“/home/bin/hogdescriptor.xml”))
{
std::cout这是我得到的最接近的东西…仍在尝试使用此xml
private static void buscar_hog_svm() {
if (clasificador == null) {
clasificador = new CvSVM();
clasificador.load(path_vectores);
}
Mat img_gray = new Mat();
//gray
Imgproc.cvtColor(imag, img_gray, Imgproc.COLOR_BGR2GRAY);
//Extract HogFeature
hog = new HOGDescriptor(
_winSize //new Size(32, 16)
, _blockSize, _blockStride, _cellSize, _nbins);
MatOfFloat descriptorsValues = new MatOfFloat();
MatOfPoint locations = new MatOfPoint();
hog.compute(img_gray,
descriptorsValues,
_winSize,
_padding, locations);
Mat fm = descriptorsValues;
System.out.println("tamano fm: " + fm.size());
//Classification whether data is positive or negative
float result = clasificador.predict(fm);
System.out.println("resultado= " + result);
}
如果你有更多的线索,请分享
private static void buscar_hog_svm() {
if (clasificador == null) {
clasificador = new CvSVM();
clasificador.load(path_vectores);
}
Mat img_gray = new Mat();
//gray
Imgproc.cvtColor(imag, img_gray, Imgproc.COLOR_BGR2GRAY);
//Extract HogFeature
hog = new HOGDescriptor(
_winSize //new Size(32, 16)
, _blockSize, _blockStride, _cellSize, _nbins);
MatOfFloat descriptorsValues = new MatOfFloat();
MatOfPoint locations = new MatOfPoint();
hog.compute(img_gray,
descriptorsValues,
_winSize,
_padding, locations);
Mat fm = descriptorsValues;
System.out.println("tamano fm: " + fm.size());
//Classification whether data is positive or negative
float result = clasificador.predict(fm);
System.out.println("resultado= " + result);
}