本文整理汇总了C++中HOGDescriptor类的典型用法代码示例。如果您正苦于以下问题:C++ HOGDescriptor类的具体用法?C++ HOGDescriptor怎么用?C++ HOGDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HOGDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PERF_TEST
PERF_TEST(HOGFixture, HOG)
{
Mat src = imread(getDataPath("gpu/hog/road.png"), cv::IMREAD_GRAYSCALE);
ASSERT_TRUE(!src.empty()) << "can't open input image road.png";
vector<cv::Rect> found_locations;
declare.in(src).time(5);
if (RUN_PLAIN_IMPL)
{
HOGDescriptor hog;
hog.setSVMDetector(hog.getDefaultPeopleDetector());
TEST_CYCLE() hog.detectMultiScale(src, found_locations);
std::sort(found_locations.begin(), found_locations.end(), RectLess());
SANITY_CHECK(found_locations, 1 + DBL_EPSILON);
}
else if (RUN_OCL_IMPL)
{
ocl::HOGDescriptor ocl_hog;
ocl_hog.setSVMDetector(ocl_hog.getDefaultPeopleDetector());
ocl::oclMat oclSrc(src);
OCL_TEST_CYCLE() ocl_hog.detectMultiScale(oclSrc, found_locations);
std::sort(found_locations.begin(), found_locations.end(), RectLess());
SANITY_CHECK(found_locations, 1 + DBL_EPSILON);
}
else
OCL_PERF_ELSE
}
示例2: test_trained_detector
int test_trained_detector( String obj_det_filename, String test_dir, String videofilename )
{
cout << "Testing trained detector..." << endl;
HOGDescriptor hog;
hog.load( obj_det_filename );
vector< String > files;
glob( test_dir, files );
int delay = 0;
VideoCapture cap;
if ( videofilename != "" )
{
cap.open( videofilename );
}
obj_det_filename = "testing " + obj_det_filename;
namedWindow( obj_det_filename, WINDOW_NORMAL );
for( size_t i=0;; i++ )
{
Mat img;
if ( cap.isOpened() )
{
cap >> img;
delay = 1;
}
else if( i < files.size() )
示例3: load_images
void load_images(const string & filename, int label) {
HOGDescriptor hog;
hog.winSize = size;
string line;
ifstream file;
vector<float> descriptors;
vector<Point> locations;
file.open(filename.c_str());
if (!file.is_open()) {
cout << "file cannot be opened" << endl;
exit(-1);
}
while (true) {
getline(file, line);
if (line == "") {
break;
}
Mat img = imread(line.c_str(), 0);
if (img.empty())
continue;
resize(img, img, size);
hog.compute(img, descriptors, Size(8, 8), Size(0, 0), locations);
training_list.push_back(Mat(descriptors).clone());
training_label.push_back(label);
img.release();
}
cout << training_list.size() << endl;
cout << training_label.size() << endl;
}
示例4: computeHOGs
void computeHOGs( const Size wsize, const vector< Mat > & img_lst, vector< Mat > & gradient_lst, bool use_flip )
{
HOGDescriptor hog;
hog.winSize = wsize;
Mat gray;
vector< float > descriptors;
for( size_t i = 0 ; i < img_lst.size(); i++ )
{
if ( img_lst[i].cols >= wsize.width && img_lst[i].rows >= wsize.height )
{
Rect r = Rect(( img_lst[i].cols - wsize.width ) / 2,
( img_lst[i].rows - wsize.height ) / 2,
wsize.width,
wsize.height);
cvtColor( img_lst[i](r), gray, COLOR_BGR2GRAY );
hog.compute( gray, descriptors, Size( 8, 8 ), Size( 0, 0 ) );
gradient_lst.push_back( Mat( descriptors ).clone() );
if ( use_flip )
{
flip( gray, gray, 1 );
hog.compute( gray, descriptors, Size( 8, 8 ), Size( 0, 0 ) );
gradient_lst.push_back( Mat( descriptors ).clone() );
}
}
}
}
示例5: hog
int hog(string name, int i)
{
int ImgWidht = 120;
int ImgHeight = 120;
Mat src;
Mat trainImg = Mat::zeros(ImgHeight, ImgWidht, CV_8UC3);//需要分析的图片
src = imread(name.c_str(), 1);
//cout << "HOG: processing " << name.c_str() << endl;
resize(src, trainImg, cv::Size(ImgWidht, ImgHeight), 0, 0, INTER_CUBIC);
HOGDescriptor *hog = new HOGDescriptor(cvSize(ImgWidht, ImgHeight), cvSize(16, 16), cvSize(8, 8), cvSize(8, 8), 9);
vector<float>descriptors;//结果数组
hog->compute(trainImg, descriptors, Size(1, 1), Size(0, 0)); //调用计算函数开始计算
if (i == 0)
{
//descSize = descriptors.size();
data_mat = Mat::zeros(nLine, descriptors.size(), CV_32FC1); //根据输入图片大小进行分配空间
//fusion_mat = Mat::zeros(nLine, descriptors.size() + MATSIZE + GLCMSIZE, CV_32FC1);
}
int n = 0;
for (vector<float>::iterator iter = descriptors.begin(); iter != descriptors.end(); iter++)
{
data_mat.at<float>(i, n) = *iter;
//fusion_mat.at<float>(i, n) = *iter;
n++;
}
//cout << "HOG: end processing " << name.c_str() << endl;
delete hog;
return 0;
}
示例6: LOGD
JNIEXPORT void JNICALL Java_org_opencv_objdetect_HOGDescriptor_compute_10
(JNIEnv* env, jclass , jlong self, jlong img_nativeObj, jlong descriptors_mat_nativeObj, jdouble winStride_width, jdouble winStride_height, jdouble padding_width, jdouble padding_height, jlong locations_mat_nativeObj)
{
static const char method_name[] = "objdetect::compute_10()";
try {
LOGD("%s", method_name);
vector<float> descriptors;
Mat& descriptors_mat = *((Mat*)descriptors_mat_nativeObj);
vector<Point> locations;
Mat& locations_mat = *((Mat*)locations_mat_nativeObj);
Mat_to_vector_Point( locations_mat, locations );
HOGDescriptor* me = (HOGDescriptor*) self; //TODO: check for NULL
Mat& img = *((Mat*)img_nativeObj);
Size winStride((int)winStride_width, (int)winStride_height);
Size padding((int)padding_width, (int)padding_height);
me->compute( img, descriptors, winStride, padding, locations );
vector_float_to_Mat( descriptors, descriptors_mat );
return;
} catch(const std::exception &e) {
throwJavaException(env, &e, method_name);
} catch (...) {
throwJavaException(env, 0, method_name);
}
return;
}
开发者ID:DapengLan,项目名称:Preparation-of-Augmented-Reality-with-OpenCV-and-Aruco,代码行数:25,代码来源:objdetect.cpp
示例7: imread
void kNNSearcher::kNNSearchWithHOG(const Mat &inputImage, const QStringList &imPath,
Mat &indexes, Mat &weights, int k)
{
//resize inputImage to the same size of training image
Mat temp = imread( imPath[0].toLocal8Bit().data(), CV_LOAD_IMAGE_GRAYSCALE );
Mat inputIm;
resize( inputImage, inputIm, temp.size() );
//compute the HOG descriptor of target image
HOGDescriptor *hogDesr = new HOGDescriptor( cvSize( 640, 480 ), cvSize( 160, 120 ), cvSize( 160,120 ), cvSize( 160, 120 ), 9 );
std::vector<float> targetDescriptor;
hogDesr->compute( inputIm, targetDescriptor, Size( 0, 0 ), Size( 0, 0) );
//###################################################################################
//load the training descriptors into descriptorMat if there exist a HOGof44blocks.yaml file
//otherwise, execute the train program
Mat descriptorMat;
QString const HOGMatfile = "HOGof44blocks.yaml";
FileStorage fs;
fs.open( HOGMatfile.toLocal8Bit().data(), FileStorage::READ );
if( fs.isOpened() ){
// the HOGof44blocks.yaml does exist
fs["HOGMat"] >> descriptorMat;
}else{
示例8: detectTrainingSetTest
/**
* Test the trained detector against the same training set to get an approximate idea of the detector.
* Warning: This does not allow any statement about detection quality, as the detector might be overfitting.
* Detector quality must be determined using an independent test set.
* @param hog
*/
static void detectTrainingSetTest(const HOGDescriptor& hog, const double hitThreshold, const vector<string>& posFileNames, const vector<string>& negFileNames) {
unsigned int truePositives = 0;
unsigned int trueNegatives = 0;
unsigned int falsePositives = 0;
unsigned int falseNegatives = 0;
vector<Point> foundDetection;
// Walk over positive training samples, generate images and detect
for (vector<string>::const_iterator posTrainingIterator = posFileNames.begin(); posTrainingIterator != posFileNames.end(); ++posTrainingIterator) {
const Mat imageData = imread(*posTrainingIterator, 0);
hog.detect(imageData, foundDetection, hitThreshold, winStride, trainingPadding);
if (foundDetection.size() > 0) {
++truePositives;
falseNegatives += foundDetection.size() - 1;
} else {
++falseNegatives;
}
}
// Walk over negative training samples, generate images and detect
for (vector<string>::const_iterator negTrainingIterator = negFileNames.begin(); negTrainingIterator != negFileNames.end(); ++negTrainingIterator) {
const Mat imageData = imread(*negTrainingIterator, 0);
hog.detect(imageData, foundDetection, hitThreshold, winStride, trainingPadding);
if (foundDetection.size() > 0) {
falsePositives += foundDetection.size();
} else {
++trueNegatives;
}
}
printf("Results:\n\tTrue Positives: %u\n\tTrue Negatives: %u\n\tFalse Positives: %u\n\tFalse Negatives: %u\n", truePositives, trueNegatives, falsePositives, falseNegatives);
}
示例9: Hog
vector<float> Hog(Mat image)
{
vector<float> descriptors;
HOGDescriptor* hog = new HOGDescriptor(cvSize(60, 60), cvSize(10, 10), cvSize(5, 5), cvSize(5, 5), 9);
hog->compute(image,descriptors, Size(1, 1), Size(0, 0));
return descriptors;
}
示例10: getFeatureFromImg
bool getFeatureFromImg(Mat img,vector<float> &feature)
{
HOGDescriptor hog;
hog.winSize=Size(img.cols,img.rows);
Size winStride=Size(16,16);
hog.compute(img,feature,winStride);
return true;
}
示例11: gsl_rng_env_setup
particleFilter::particleFilter() {
totalParticles = 300;
gsl_rng_env_setup();
rng = gsl_rng_alloc(gsl_rng_mt19937);
gsl_rng_set(rng, time(NULL));
vector<CvRect> region;
vector<float> descriptorVector = getDescriptorVectorFromFile(descriptorVectorFile);
HOGDescriptor hog;
hog.winSize = Size(24, 48);
hog.blockStride = Size(1,2);
hog.setSVMDetector(descriptorVector);
}
示例12: testHOG
int testHOG(Mat data, Mat res)
{
CvSVM svm;
CvSVMParams param;
CvTermCriteria criteria;
criteria = cvTermCriteria(CV_TERMCRIT_EPS, 1000, FLT_EPSILON);
param = CvSVMParams(CvSVM::C_SVC, CvSVM::LINEAR, 10.0, 0.1, 0.09, 100.0, 0.5, 1.0, NULL, criteria);//for hog
svm.train(data, res, Mat(), Mat(), param);
int ImgWidth = 120;
int ImgHeight = 120;
string buf;
vector<string> img_tst_path;
ifstream img_tst("SVM_TEST.txt");
while (img_tst)
{
if (getline(img_tst, buf))
{
img_tst_path.push_back(buf);
}
}
img_tst.close();
Mat test;
Mat trainImg = Mat::zeros(ImgHeight, ImgWidth, CV_8UC3);//需要分析的图片
char line[512];
ofstream predict_txt("SVM_PREDICT_HOG.txt");
for (string::size_type j = 0; j != img_tst_path.size(); j++)
{
test = imread(img_tst_path[j].c_str(), 1);//读入图像
resize(test, trainImg, cv::Size(ImgWidth, ImgHeight), 0, 0, INTER_CUBIC);//要搞成同样的大小才可以检测到
HOGDescriptor *hog = new HOGDescriptor(cvSize(ImgWidth, ImgHeight), cvSize(16, 16), cvSize(8, 8), cvSize(8, 8), 9);
vector<float>descriptors;//结果数组
hog->compute(trainImg, descriptors, Size(1, 1), Size(0, 0)); //调用计算函数开始计算
cout << "The Detection Result:" << endl;
Mat SVMtrainMat = Mat::zeros(1, descriptors.size(), CV_32FC1);
int n = 0;
for (vector<float>::iterator iter = descriptors.begin(); iter != descriptors.end(); iter++)
{
SVMtrainMat.at<float>(0, n) = *iter;
n++;
}
int ret = svm.predict(SVMtrainMat);
res_hog.push_back(ret);
std::sprintf(line, "%s\t%d\n", img_tst_path[j].c_str(), ret);
printf("%s %d\n", img_tst_path[j].c_str(), ret);
predict_txt << line;
delete hog;
}
predict_txt.close();
return 0;
}
示例13: getSVMDetector
HOGDescriptor HOGTrainer::getHOG() {
if (trained != "") {
Ptr<SVM> svm = StatModel::load<SVM>(trained);
HOGDescriptor hog;
hog.winSize = size;
vector<float> hogDetector;
getSVMDetector(svm, hogDetector);
hog.setSVMDetector(hogDetector);
return hog;
}
return cv::HOGDescriptor();
}
示例14: test_it
void test_it( const Size & size )
{
char key = 27;
Scalar reference( 0, 255, 0 );
Scalar trained( 0, 0, 255 );
Mat img, draw;
Ptr<SVM> svm;
HOGDescriptor hog;
HOGDescriptor my_hog;
my_hog.winSize = size;
VideoCapture video;
vector< Rect > locations;
// Load the trained SVM.
svm = StatModel::load<SVM>( "my_people_detector.yml" );
// Set the trained svm to my_hog
vector< float > hog_detector;
get_svm_detector( svm, hog_detector );
my_hog.setSVMDetector( hog_detector );
// Set the people detector.
hog.setSVMDetector( hog.getDefaultPeopleDetector() );
// Open the camera.
video.open(0);
if( !video.isOpened() )
{
cerr << "Unable to open the device 0" << endl;
exit( -1 );
}
bool end_of_process = false;
while( !end_of_process )
{
video >> img;
if( img.empty() )
break;
draw = img.clone();
locations.clear();
hog.detectMultiScale( img, locations );
draw_locations( draw, locations, reference );
locations.clear();
my_hog.detectMultiScale( img, locations );
draw_locations( draw, locations, trained );
imshow( "Video", draw );
key = (char)waitKey( 10 );
if( 27 == key )
end_of_process = true;
}
}
示例15: HogDetectPeople
vector<Rect> HogDetectPeople(Mat img)
{
HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
fflush(stdout);
vector<Rect> found, found_filtered;
double t = (double)getTickCount();
// run the detector with default parameters. to get a higher hit-rate
// (and more false alarms, respectively), decrease the hitThreshold and
// groupThreshold (set groupThreshold to 0 to turn off the grouping completely).
hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);
t = (double)getTickCount() - t;
printf("tdetection time = %gms\n", t*1000./cv::getTickFrequency());
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];
// the HOG detector returns slightly larger rectangles than the real objects.
// so we slightly shrink the rectangles to get a nicer output.
r.x += cvRound(r.width*0.1);
r.width = cvRound(r.width*0.8);
r.y += cvRound(r.height*0.07);
r.height = cvRound(r.height*0.8);
if(r.x+r.width>img.cols-1)
{ r.x=img.cols-1-r.width;}
if(r.x<0)
r.x=0;
if(r.y+r.height>img.rows-1)
r.y=img.rows-1-r.height;
if(r.y<0)
r.y=0;
found_filtered[i].x=r.x;
found_filtered[i].y=r.y;
found_filtered[i].width=r.width;
found_filtered[i].height=r.height;
// rectangle(img, r.tl(), r.br(), cv::Scalar(0,255,0), 3);
}
return found_filtered;
}