2016-10-14 7 views
0

私はこのプログラムをOpenCVを使ってC++で書いて、私が持っているpedestrians.xmlというファイルを検出しました。プログラムは、入力画像のすべてを読み取って、歩行者が位置する出力画像に青色の長方形を表示する必要があります。しかし、コードは私にエラーを与えています。なぜこれらのエラーが来るのか教えてくれる人はいますか?CascadeClassifier openCV

#include <opencv2/core/core.hpp> 
#include <opencv2/highgui/highgui.hpp> 
#include <opencv2/imgproc/imgproc.hpp> 
#include <opencv2/features2d/features2d.hpp> 
#include<iostream> 
#include <stdio.h> 
#include <string> 
#include <vector> 

using namespace std; 
using namespace cv; 

void detectAndDisplay(Mat frame); 

/** Global variables */ 
String pedestrians_name = "hogcascade_pedestrians.xml"; 
//CascadeClassifier pedestrians; 
string window_name = "Capture - pedestrians detection"; 
RNG rng(12345); 

/** @function main */ 
int main(int argc, const char** argv) 
{ 
    CvCapture* capture; 
    Mat frame; 

    //-- 1. Load the cascades 
    //if(!pedestrians.load(pedestrians_name)){ printf("--(!)Error loading\n"); return -1; }; 
    Mat image = imread("ped1.jpg"); 
    Mat image_keypoints; 
    cvtColor(image, image_keypoints, CV_BGR2GRAY); 

    return 0; 
} 

/** @function detectAndDisplay */ 
void detectAndDisplay(Mat frame) 
{ 
    std::vector<Rect> pedestrians; 
    Mat frame_gray; 

    cvtColor(frame, frame_gray, CV_BGR2GRAY); 
    equalizeHist(frame_gray, frame_gray); 

    //-- Detect faces 
    pedestrians.detectMultiScale(frame_gray, pedestrians, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30)); 
    void CascadeClassifier::detectMultiScale(const Mat& image, vector<Rect>& objects, double scaleFactor=1.1, int minNeighbors=3, int flags=0, Size minSize=Size(), Size maxSize=Size()); 

    for(int i = 0; i < pedestrians.size(); i++) 
    { 
    Point center(pedestrians[i].x + pedestrians[i].width*0.5, pedestrians[i].y + pedestrians[i].height*0.5); 
    ellipse(frame, center, Size(pedestrians[i].width*0.5, pedestrians[i].height*0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0); 

    Mat faceROI = frame_gray(pedestrians[i]); 
    std::vector<Rect> eyes; 

    //-- In each face, detect eyes 
    /*eyes_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30)); 

    for(size_t j = 0; j < eyes.size(); j++) 
    { 
     Point center(faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5); 
     int radius = cvRound((eyes[j].width + eyes[j].height)*0.25); 
     circle(frame, center, radius, Scalar(255, 0, 0), 4, 8, 0); 
    }*/ 
    } 
    //-- Show what you got 
    imshow(window_name, frame); 
} 

これらはエラーです:

cascade.cpp: In function âvoid detectAndDisplay(cv::Mat)â: 
cascade.cpp:46: error: âclass std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >â has no member named âdetectMultiScaleâ 
cascade.cpp:46: error: âCV_HAAR_SCALE_IMAGEâ was not declared in this scope 
cascade.cpp:47: error: âCascadeClassifierâ has not been declared 
cascade.cpp:47: error: invalid use of qualified-name â<declaration error>::detectMultiScaleâ 

答えて

0

あなたがopencv_objdetectライブラリを追加する必要があります。また、 "opencv2/objdetect.hpp"も含めてください。

+0

私はこのライブラリを追加したが、あなたは方法再宣言なかったのはなぜエラーがまだ –

+0

出現:無効CascadeClassifierを:: detectMultiScale(constのマット&画像、ベクトル&オブジェクト、ダブルscaleFactorを= 1.1、INT minNeighbors = 3、int型のフラグ= 0、Size minSize = Size()、Size maxSize = Size()); 関数detectAndDisplayですか?それは非常に奇妙に見えます。 –

0

あなたはdetectAndDisplay()が右と呼ばれることはありません?)カスケード分類器オブジェクトを作成し、XMLファイルobj.load(xmlファイル・パス)メイン内のすべての

0

まず、(ロード

さらに、detectMultiScaleを使用する前に、detectAndDisplay()でカスケード分類子を宣言してロードする必要があります。

CascadeClassifier pedestrians; 
if(!pedestrians.load(pedestrians_name)){ 
printf("--(!)Error loading\n"); 
return;} 
//..... 
pedestrians.detectMultiScale(frame_gray, pedestrians, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30)); 
関連する問題