int main() { //VideoCapture video("E:\\C_VC_code\\Text_Photo\\feini.flv"); VideoCapture video(0); if(!video.isOpened()) { return 0; } vector<float>head; FILE *read = fopen("detector_TQ.txt","r"); if(read==NULL) { cout<<"Error: The file read fail"<<endl; return -1; } double data; while(fscanf(read,"%lf",&data)!=-1) { head.push_back(data); } cout<<head.size() <<endl; Mat img,dstimg; vector<cv::Rect>found; HOGDescriptor hog(Size(48,48),Size(16,16),Size(8,8),Size(8,8),9); hog.setSVMDetector(head); double scalar = 0.5; while(1) { video>>img; resize(img,dstimg,Size(img.cols*scalar,img.rows*scalar),1,1,3); hog.detectMultiScale(dstimg, found, 1, cv::Size(8,8), cv::Size(0,0), 1.1, 3, false); for(int i=0;i<found.size();i++) { Rect r=found[i]; r.x/=scalar; r.y/=scalar; r.width/=scalar; r.height/=scalar; rectangle(img,r,CV_RGB(0,255,0),2); } imshow("video1",dstimg); imshow("video",img); found.clear(); if(waitKey(33)==27) { imshow("video",img); waitKey(0); break; } } }
原文:http://www.cnblogs.com/mypsq/p/5003416.html