本文整理汇总了C++中HOGDescriptor::compute方法的典型用法代码示例。如果您正苦于以下问题:C++ HOGDescriptor::compute方法的具体用法?C++ HOGDescriptor::compute怎么用?C++ HOGDescriptor::compute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HOGDescriptor
的用法示例。
在下文中一共展示了HOGDescriptor::compute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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() );
}
}
}
}
示例2: 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;
}
示例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: 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;
}
示例5: calculateFeaturesFromInput
/**
* This is the actual calculation from the (input) image data to the HOG descriptor/feature vector using the hog.compute() function
* @param imageFilename file path of the image file to read and calculate feature vector from
* @param descriptorVector the returned calculated feature vector<float> ,
* I can't comprehend why openCV implementation returns std::vector<float> instead of cv::MatExpr_<float> (e.g. Mat<float>)
* @param hog HOGDescriptor containin HOG settings
*/
static void calculateFeaturesFromInput(const string& imageFilename, vector<float>& featureVector, HOGDescriptor& hog) {
/** for imread flags from openCV documentation,
* @see http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#Mat imread(const string& filename, int flags)
* @note If you get a compile-time error complaining about following line (esp. imread),
* you either do not have a current openCV version (>2.0)
* or the linking order is incorrect, try g++ -o openCVHogTrainer main.cpp `pkg-config --cflags --libs opencv`
*/
Mat imageData = imread(imageFilename, 0);
if (imageData.empty()) {
featureVector.clear();
printf("Error: HOG image '%s' is empty, features calculation skipped!\n", imageFilename.c_str());
return;
}
// hack: change dimensions
//Size size(32,64);
//resize(imageData, imageData, size);
// Check for mismatching dimensions
if (imageData.cols != hog.winSize.width || imageData.rows != hog.winSize.height) {
featureVector.clear();
printf("Error: Image '%s' dimensions (%u x %u) do not match HOG window size (%u x %u)!\n", imageFilename.c_str(), imageData.cols, imageData.rows, hog.winSize.width, hog.winSize.height);
return;
}
vector<Point> locations;
hog.compute(imageData, featureVector, winStride, trainingPadding, locations);
imageData.release(); // Release the image again after features are extracted
}
示例6: kNNSearchWithHOG
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{
示例7: RecognizeLight
//not using hole traffic ligh as samples,just use the square light
int RecognizeLight(IplImage* srcImg,CvRect iRect)
{
CvSize cutSize;
cutSize.width=iRect.width;
cutSize.height=iRect.height;
IplImage *tmpCutImg=cvCreateImage(cutSize,srcImg->depth,srcImg->nChannels);
GetImageRect(srcImg,iRect,tmpCutImg);
#if IS_CUTIMG
cvShowImage("tmpCutImg",tmpCutImg);
cvWaitKey(1);
char tmpName[100];
static int ppp=0;
ppp++;
sprintf_s(tmpName,"ImgCut//%d.jpg",ppp);
cvSaveImage(tmpName,tmpCutImg);
#endif
Mat cutMat(tmpCutImg);
Mat tmpTLRec;
vector<float> descriptor;
//识别信号灯类别
resize(cutMat,tmpTLRec,Size(TLREC_WIDTH,TLREC_HEIGHT));
TLRecHOG.compute(tmpTLRec,descriptor,Size(8,8));
int DescriptorDim=descriptor.size();
Mat SVMTLRecMat(1,DescriptorDim,CV_32FC1);
for(int i=0; i<DescriptorDim; i++)
SVMTLRecMat.at<float>(0,i) = descriptor[i];
int result=TLRecSVM.predict(SVMTLRecMat);
cvReleaseImage(&tmpCutImg);
return result;
}
示例8: winStride
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
示例9: cpu_desc
OCL_TEST_P(HOG, GetDescriptors)
{
HOGDescriptor hog;
hog.gammaCorrection = true;
hog.setSVMDetector(hog.getDefaultPeopleDetector());
std::vector<float> cpu_descriptors;
std::vector<float> gpu_descriptors;
OCL_OFF(hog.compute(img, cpu_descriptors, hog.winSize));
OCL_ON(hog.compute(uimg, gpu_descriptors, hog.winSize));
Mat cpu_desc(cpu_descriptors), gpu_desc(gpu_descriptors);
EXPECT_MAT_SIMILAR(cpu_desc, gpu_desc, 1e-1);
}
示例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: 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;
}
示例12: isTL
int isTL(IplImage* srcImg,CvRect iRect,bool isVertical)
{
CvSize cutSize;
cutSize.width=iRect.width;
cutSize.height=iRect.height;
IplImage *tmpCutImg=cvCreateImage(cutSize,srcImg->depth,srcImg->nChannels);
GetImageRect(srcImg,iRect,tmpCutImg);
Mat cutMat(tmpCutImg);
Mat tmpIsTL;
vector<float> descriptor;
//识别信号灯类别
if (isVertical){
resize(cutMat, tmpIsTL, Size(HOG_TLVertical_Width, HOG_TLVertical_Height));
myHOG_vertical.compute(tmpIsTL, descriptor, Size(8, 8));
}
else{
resize(cutMat, tmpIsTL, Size(HOG_TLHorz_Width, HOG_TLHorz_Height));
myHOG_horz.compute(tmpIsTL, descriptor, Size(8, 8));
}
int DescriptorDim=descriptor.size();
Mat SVMTLRecMat(1,DescriptorDim,CV_32FC1);
for(int i=0; i<DescriptorDim; i++)
SVMTLRecMat.at<float>(0,i) = descriptor[i];
//int result=isTLSVM.predict(SVMTLRecMat);
int result = 0;
if (isVertical)
result = isVerticalTLSVM.predict(SVMTLRecMat);
else
{
result = isHorzTLSVM.predict(SVMTLRecMat);
}
cvReleaseImage(&tmpCutImg);
return result;
}
示例13: main
int main()
{
Mat test;
char result[300]; //存放預測結果
//Ptr<ml::SVM> svm = ml::SVM::create();
//svm->Algorithm::load<ml::SVM>("HOG_SVM_DATA.xml");//加仔訓練好的數字,這裡是10K手寫數字
Ptr<ml::SVM> svm = ml::SVM::load("HOG_SVM_DATA.xml");
//檢測樣本
test = imread("test.bmp", 1); //測試圖片
if (test.empty())
{
cout << "not exist" << endl;
return -1;
}
cout << "load image done" << endl;
Mat trainTempImg= Mat::zeros(28, 28, CV_32F);
resize(test, trainTempImg, Size(28, 28));
HOGDescriptor *hog = new HOGDescriptor(cvSize(28, 28), cvSize(14, 14), cvSize(7, 7), cvSize(7, 7), 9);
vector<float>descriptors;//存放結果
hog->compute(trainTempImg, descriptors, Size(1, 1), Size(0, 0)); //Hog特徵計算
cout << "HOG dims: " << descriptors.size() << endl; //印出Hog特徵維數,這裡是324
Mat SVMtrainMat(1, descriptors.size(), CV_32F);
int n = 0;
for (vector<float>::iterator iter = descriptors.begin(); iter != descriptors.end(); iter++)
{
//cvmSet(SVMtrainMat, 0, n, *iter);
SVMtrainMat.at<float>(n) = *iter;
n++;
}
//int count = svm->getVarCount();
//cout << count << " " << SVMtrainMat.cols << endl;
//count = SVMtrainMat.type();
//cout << count << endl;
//cout << svm->getVarCount() << " " << SVMtrainMat.cols << endl;
int ret = svm->predict(SVMtrainMat);//檢測結果
sprintf_s(result, "%d\r\n", ret);
namedWindow("dst", 1);
imshow("dst", test);
cout << "result:" << result << endl;
waitKey();
return 0;
}
示例14: compute_hog
void compute_hog(const vector< Mat > & img_lst, vector< Mat > & gradient_lst, const Size & size){
HOGDescriptor hog;
hog.winSize = size;
Mat gray;
vector< Point > location;
vector< float > descriptors;
vector< Mat >::const_iterator img = img_lst.begin();
vector< Mat >::const_iterator end = img_lst.end();
for (; img != end; ++img){
cvtColor(*img, gray, COLOR_BGR2GRAY);
equalizeHist(gray, gray);
hog.compute(gray, descriptors, Size(8, 8), Size(0, 0), location);
Mat tmpImg = Mat(descriptors).clone();
//gradient_lst.push_back(Mat(descriptors).clone());
gradient_lst.push_back(tmpImg);
}
}
示例15: load_test_images
void load_test_images(const string & filename, int rLabel) {
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;
Mat noise = Mat(img.size(), img.type());
randn(noise, 0, 50);
img = img + noise;
// imshow("img",img);
// waitKey();
resize(img, img, size);
hog.compute(img, descriptors, Size(8, 8), Size(0, 0), locations);
test_list.push_back(Mat(descriptors).clone());
test_label.push_back(rLabel);
img.release();
}
cout << test_list.size() << endl;
cout << test_label.size() << endl;
}