我需要检测图片中的人物。在这里,我使用haar级联来检测身体。但是,结果显示没有变化。图像上没有矩形,所以我想知道发生了什么。
int main(int argc, char** argv)
{
argv[1] = "C:/people.jpg";//test image
Mat image;
Mat img;
Mat gray;
vector<Rect>human;
CascadeClassifier detectorBody;
string cascadeBody = "C:/opencv/opencv/sources/data/haarcascades_cuda/haarcascade_fullbody.xml";
bool loaded = detectorBody.load(cascadeBody);
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);
cvtColor(image, gray, CV_BGR2GRAY);//turn to gray
detectorBody.detectMultiScale(gray, human, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(12, 28));
for (int i = 0; i < human.size(); i++) {
rectangle(gray, human[i].tl(), human[i].br(), Scalar(0, 0, 255), 2, 8, 0);
}
namedWindow("Display", CV_WINDOW_NORMAL);
imshow("Display", image);
namedWindow("gray", CV_WINDOW_NORMAL);
imshow("gray", gray);
waitKey(0);
return 0;
}