本文整理汇总了C++中HOGDescriptor::detectMultiScale方法的典型用法代码示例。如果您正苦于以下问题:C++ HOGDescriptor::detectMultiScale方法的具体用法?C++ HOGDescriptor::detectMultiScale怎么用?C++ HOGDescriptor::detectMultiScale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HOGDescriptor
的用法示例。
在下文中一共展示了HOGDescriptor::detectMultiScale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
vector<Rect> detect(InputArray img)
{
// 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).
vector<Rect> found;
if (m == Default)
hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2, false);
else if (m == Daimler)
hog_d.detectMultiScale(img, found, 0.5, Size(8,8), Size(32,32), 1.05, 2, true);
return found;
}
示例2: detectTest
/**
* Test detection with custom HOG description vector
* @param hog
* @param hitThreshold threshold value for detection
* @param imageData
*/
static void detectTest(const HOGDescriptor& hog, const double hitThreshold, Mat& imageData) {
vector<Rect> found;
Size padding(Size(8, 8));
Size winStride(Size(8, 8));
hog.detectMultiScale(imageData, found, hitThreshold, winStride, padding);
showDetections(found, imageData);
}
示例3: if
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
}
示例4: detectTest
/**
* Test detection with custom HOG description vector
* @param hog
* @param hitThreshold threshold value for detection
* @param imageData
*/
static void detectTest(const HOGDescriptor& hog, const double hitThreshold, Mat& imageData, vector<Rect>& found, vector<double>& weights) {
//vector<Rect> found;
Size padding(Size(32, 32));
Size winStride(Size(8, 8));
hog.detectMultiScale(imageData, found, weights, hitThreshold, winStride, padding, 1.05, 1);
showDetections(found, imageData);
}
示例5: consumer
/*
* === FUNCTION ======================================================================
* Name: consumer
* Description: 处理图像线程,计算hog和显示
* =====================================================================================
*/
void consumer(void)
{
while (true){
vector<Rect> found, found_filtered;
spsc_queue.pop(showimg);
hog.detectMultiScale(showimg, found, 0, Size(4,4), Size(0,0), 1.05, 2);
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(showimg, r.tl(), r.br(), cv::Scalar(0,255,0), 1);
}
imshow("1",showimg);
waitKey(5);
}
}
示例6: detectPeople
void detectPeople(Mat frame, bool isFlip) {
vector<Rect> found, found_filtered;
// we shouldn't need to flip anything - if we always use landscape mode
if (isFlip) {
Mat flippedFrame;
flip(frame, flippedFrame, 1);
flippedFrame.copyTo(frame);
}
hog.detectMultiScale(frame, found, 0, Size(8,8), Size(32,32), 1.05, 2);
LOGD("found %d", found.size());
for (int i = 0; i < found.size(); ++i) {
Rect r = found[i];
int j = 0;
for (; j < found.size(); ++j) {
// what does & mean for Rect?
if (j != i && (r & found[j]) == r) {
break;
}
}
if (j == found.size()) {
found_filtered.push_back(r);
}
}
for (int i = 0; i < found_filtered.size(); ++i) {
Rect r = found_filtered[i];
rectangle(frame, r.tl(), r.br(), Scalar(255,0,0), 3);
}
}
示例7: detectSat
void detectSat(HOGDescriptor& hog, const double hitThreshold, Mat& imageData, CircleData& cercle)
{
vector<Rect> found;
Size padding(Size(4, 4));
Size winStride(Size(2, 2));
hog.detectMultiScale(imageData, found, hitThreshold, winStride, padding);
showDetections(found, imageData, cercle);
}
示例8: detectTest
/**
* Test detection with custom HOG description vector
* @param hog
* @param imageData
*/
static void detectTest(const HOGDescriptor& hog, Mat& imageData) {
vector<Rect> found;
int groupThreshold = 2;
Size padding(Size(32, 32));
Size winStride(Size(8, 8));
double hitThreshold = 0.; // tolerance
hog.detectMultiScale(imageData, found, hitThreshold, winStride, padding, 1.05, groupThreshold);
showDetections(found, imageData);
}
示例9: Size
OCL_TEST_P(HOG, Detect)
{
HOGDescriptor hog;
hog.winSize = winSize;
hog.gammaCorrection = true;
if (winSize.width == 48 && winSize.height == 96)
hog.setSVMDetector(hog.getDaimlerPeopleDetector());
else
hog.setSVMDetector(hog.getDefaultPeopleDetector());
std::vector<Rect> cpu_found;
std::vector<Rect> gpu_found;
OCL_OFF(hog.detectMultiScale(img, cpu_found, 0, Size(8, 8), Size(0, 0), 1.05, 6));
OCL_ON(hog.detectMultiScale(uimg, gpu_found, 0, Size(8, 8), Size(0, 0), 1.05, 6));
EXPECT_LT(checkRectSimilarity(img.size(), cpu_found, gpu_found), 0.05);
}
示例10: 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;
}
}
示例11: 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;
}
示例12: main
int main (int argc, const char * argv[])
{
VideoCapture cap(CV_CAP_ANY);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
if (!cap.isOpened())
return -1;
Mat img;
HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
namedWindow("video capture", CV_WINDOW_AUTOSIZE);
while (true)
{
cap >> img;
if (!img.data)
continue;
vector<Rect> found, found_filtered;
hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);
//should be able to utilize found.size() as the person count
//eliminating the graphics display and plotting should
//speed things up.
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(img, r.tl(), r.br(), cv::Scalar(0,255,0), 2);
}
imshow("video capture", img);
if (waitKey(20) >= 0)
break;
}
return 0;
}
示例13: PeopleDetectByHOG
void PeopleDetectByHOG( Mat frame , Mat mask, HOGDescriptor hog)
{
Mat frame_copy = frame.clone();
if(Body_scale_factor != 1.0f) {
resize(frame_copy, frame_copy, Size(), Body_scale_factor, Body_scale_factor, INTER_AREA);
// resize(mask, mask, Size(), Body_scale_factor, Body_scale_factor, INTER_AREA);
}
// imshow("test1",frameCopy);
vector<Rect> found, found_filtered;
//do detection
//if the size of src image is too small, the program will be error as assertion fault
//the parameters here should be adjusted
hog.detectMultiScale(frame_copy, found, 0, Size(8,8), Size(32,32), 1.05, 2);
// hog.detectMultiScale(frameCopy, found);
//remove nested rectangle
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);
}
Mat drawing = Mat::zeros(frame_copy.size(),CV_8UC1);
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 = Rect_AdjustSizeAroundCenter(r,0.55,0.8);
rectangle( drawing, r.tl(), r.br(), Scalar(255,255,255), -1, 8, 0);
// rectangle( mask, r.tl(), r.br(), Scalar(255,255,255), -1, 8, 0);
}
if(Body_scale_factor != 1.0f) {
resize(drawing, drawing, Size(video_size.width,video_size.height), 0,0, INTER_NEAREST);
// resize(mask, mask, Size(), 1/Body_scale_factor, 1/Body_scale_factor, INTER_NEAREST);
}
for(int i = 0; i < mask.cols; i++)
{
for(int j = 0; j < mask.rows; j++)
{
Point p = Point(i,j);
if(drawing.at<uchar>(p) == 255)
mask.at<uchar>(p) += mask_add_step;
}
}
}
示例14: testIt
void HOGTrainer::testIt(const string fileName) {
if (trained != "") {
char key = 27;
Scalar sReference(0, 255, 0);
Scalar sTrained(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 sTrained SVM.
svm = StatModel::load<SVM>(trained);
// Set the sTrained svm to my_hog
vector<float> hog_detector;
getSVMDetector(svm, hog_detector);
my_hog.setSVMDetector(hog_detector);
// Set the people detector.
hog.setSVMDetector(hog.getDefaultPeopleDetector());
// Open the camera.
video = new VideoCapture(fileName);
if (!video->isOpened()) {
cerr << "Unable to open the device 0" << endl;
exit(-1);
}
bool end_of_process = false;
while (!end_of_process) {
video->read(img);
if (img.empty())
break;
draw = img.clone();
locations.clear();
hog.detectMultiScale(img, locations);
drawLocations(draw, locations, sReference);
locations.clear();
my_hog.detectMultiScale(img, locations);
drawLocations(draw, locations, sTrained);
imshow("Video", draw);
key = (char) waitKey(10);
if (27 == key)
end_of_process = true;
}
}
}
示例15: Run
void CvPeopleDetector::Run()
{
HOGDescriptor hog;
hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
// Get the new frame
m_img = m_pImgProcessor->GetRGBImage();
// Clear the previously detected people
m_found_filtered.clear();
std::vector<Rect> found;
cv::Size winStride(8, 8);
if (m_params.type == Params::SMALL_WIN)
{
winStride.width = 8;
winStride.height = 8;
}
else if (m_params.type == Params::MEDIUM_WIN)
{
winStride.width = 16;
winStride.height = 16;
}
else if (m_params.type == Params::LARGE_WIN)
{
winStride.width = 32;
winStride.height = 32;
}
hog.detectMultiScale(m_img, found, m_params.hitThreshold,
winStride, Size(32,32), m_params.scaleFactor, m_params.groupThreshold);
//hog.detectMultiScale(m_img, found, 0, Size(8,8), Size(32,32), 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() )
m_found_filtered.push_back(r);
}
}