HOGDescriptionr OpenCV dsize.area()断言失败
HOGDescriptor OpenCV dsize.area() assertion failed
我正在尝试训练SVM,并在OpenCV的HOGDescrpitor中使用它。
HOGDescriptionr成功地生成并加载了xml文件,但当我尝试检测某个对象时,就会出现断言:
OpenCV错误:断言失败(dsize.area()||(inv_scale_x>0&&inv_scale_y>0)),文件/build/buildd/opencv-2.48+dfsg1/modules/imgproc/src/imgwarp.cpp,行1825在抛出的实例后终止调用'tbb::captured_exception'what():/build/buildd/opencv-2.48+dfsg1/modules/imgproc/src/imgwarp.cpp:1825:错误:(-215)中的dsize.area()||(inv_scale_x>0&&inv_scale_y>0)函数调整大小
为了实现SVM训练器,我使用了使用OpenCV和带有图像的SVM的提示
生成的XML文件大约有144K字节。对于阳性和阴性样本,我使用了尺寸为64x128的图像(2000用于阳性,2000用于阴性)
SVM训练器参数:
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);
}
XML:
<?xml version="1.0"?>
<opencv_storage>
<my_svm type_id="opencv-ml-svm">
<svm_type>C_SVC</svm_type>
<kernel><type>LINEAR</type></kernel>
<C>1.</C>
<term_criteria><epsilon>2.2204460492503131e-16</epsilon>
<iterations>10000</iterations></term_criteria>
<var_all>8192</var_all>
<var_count>8192</var_count>
<class_count>2</class_count>
<class_labels type_id="opencv-matrix">
<rows>1</rows>
<cols>2</cols>
<dt>i</dt>
<data>
-1 1</data></class_labels>
<sv_total>1</sv_total>
<support_vectors>
<_>
-9.25376153e-05 -9.25376153e-05 -9.25376153e-05 -9.25376153e-05 ...and many, many...</_></support_vectors>
<decision_functions>
<_>
<sv_count>1</sv_count>
<rho>-1.</rho>
<alpha>
1.</alpha>
<index>
0</index></_></decision_functions></my_svm>
</opencv_storage>
有人能向我解释这个断言吗?或者也许能为这个问题提供一些解决方案?我花了将近3天的时间来解决这个问题,但没有任何成功。。。提前感谢!
这是我离。。。仍在尝试使用此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);
}
如果您有更多线索,请分享
相关文章:
- 尝试使用 std::vector<std::thread时出现静态断言失败错误>
- uint_not_usable_without_attribute在业力规则中使用数字生成器时静态断言失败
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- 在 CppUnit 中测试中止断言失败
- 使用扫描的调试断言失败
- 为什么我的Qt程序在断言失败后继续运行?
- 图片不显示,关闭时出错 --> 调试断言失败!表达式:is_block_type_valid(标头>_block_use)
- 访问提升:shared_ptr 主范围外崩溃,断言失败:px != 0.指针的正确用法是什么?
- C++ 调试断言失败 - 矢量下标超出视觉工作室的范围
- 错误:断言失败 (src.type() == CV_8UC1) 在阈值中
- Boost Beast 异步服务器失败,断言失败:(id_ != T::id) 在多个 aync 调用中
- 使用imwrite OpenCV时断言失败
- 调试断言失败的缓冲区!=nullptr
- 使用 ofstream 写入文本文件时断言失败
- 提升继续恢复断言失败
- 获取有关调试断言失败的错误:表达式:"(_Ptr_user &(_BIG_ALLOCATION_ALIGNMENT -1)) == 0" &&0
- OpenCV(3.4.1) 错误:断言失败(变暗 <= 2 && step[0] > 0) in cv::Mat::locateROI
- 在Win10上使用带有Qt5的OpenCV3.0,调试断言失败
- MFC GetDC() 断言失败 - "Not a window"
- OpenCV 错误:断言失败 - 矩阵减去