您好我会识别我的图片上的物品
在创建一个用 svm 进行训练的数据集之前,我只是裁剪了我的图像的单个部分,计算出的猪的描述符将它们放入svmdetector,然后尝试在原始图像上使用多尺度检测找到它。
然而,检测指出了我的图像的中心。我不确定我是否在生猪检测中做错了,或者我只是标记了错误的地方。这是我的形象
这是裁剪的一部分
这是结果
我的代码如下。
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include <math.h>
#include <iostream>
#include <stdio.h>
#include <dirent.h>
using namespace std;
using namespace cv;
int main()
{
Mat img2 = imread("part.jpg");
Mat img3 = imread("full.jpg");
HOGDescriptor d2( Size(img2.rows,img2.cols), Size(8,8), Size(4,4), Size(4,4), 9);
HOGDescriptor d3;
vector< float> descriptorsValues2,descriptorsValues3;
vector< Point> locations2,locations3;
d2.compute( img2, descriptorsValues2, Size(0,0), Size(0,0), locations2);
d2.setSVMDetector(descriptorsValues2);
vector< Rect> found,found_filtered;
d2.detectMultiScale(img3, found, 0, Size(0,0), Size(0,0), 1.05, 2);
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(img3, r.tl(), r.br(), cv::Scalar(0,255,0), 2);
}
imshow("video capture", img3);
waitKey(0);
return 0;
}
谢谢你。