Object Recognition Using Hog Features

2019-07-21 06:09发布

Hi I'm going to recognize objects on my images

Before creating a dataset to train with svm I just cropped single part of my image computed hog descriptors put them into svmdetector and then tried to find it using multiscale detection on my original image.

however detection points out center of my image. I am not sure if I'm doing something wrong with hog detection or I just mark wrong place.

this is my image

enter image description here

this is cropped part of it

enter image description here

and this is the result

enter image description here

and my code is below.

#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;
}

thank you.

0条回答
登录 后发表回答