本文介绍了使用OpenCV检测上半身部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在开发一个与OpenCV集成的iOS项目。我想要的输出是这样的: I am working on an iOS project that is integrated with OpenCV.My desired output is something like this: 如何检测上半身部位(即:从颈部到腿部)? 到目前为止,我已经完成身体检测这样的事情.. 如果有人之前做过这个。请帮助我.. How can I detect Upper Body Portion (i.e: below neck to legs)?I have done so far to achieve body detection is something like this.. If anyone has made this before.Please help me..-(void)processImage:(Mat&)image{ std::vector<cv::Rect> bodies; Mat grayscaleFrame; cvtColor(image, grayscaleFrame, CV_BGR2GRAY); equalizeHist(grayscaleFrame, grayscaleFrame); upperBodyCascade.detectMultiScale(grayscaleFrame, image, bodies, HaarOptions,cv::Size(30,30)); for (size_t i = 0; i < bodies.size(); i++) { rectangle(image, bodies[i], Scalar(255, 0, 255)); }} 推荐答案您可以使用 Haar Cascade Classifier 加载 haarcascade_upperbody.xml 您可以在此处找到示例。您只需要更改加载的分类器。You can find an example here. You just need to change the loaded classifier.代码如下:#include <opencv2/opencv.hpp>#include <iostream>using namespace std;using namespace cv;/** Function Headers */void detectAndDisplay(Mat frame);/** Global variables */String upper_body_cascade_name = "path\\to\\haarcascade_upperbody.xml";CascadeClassifier upper_body_cascade;string window_name = "Capture - Upper Body detection";RNG rng(12345);/** @function main */int main(int argc, const char** argv){ VideoCapture capture(0); Mat frame; //-- 1. Load the cascades if (!upper_body_cascade.load(upper_body_cascade_name)){ printf("--(!)Error loading\n"); return -1; }; //-- 2. Read the video stream if (capture.isOpened()) { while (true) { capture >> frame; //-- 3. Apply the classifier to the frame if (!frame.empty()) { detectAndDisplay(frame); } else { printf(" --(!) No captured frame -- Break!"); break; } int c = waitKey(10); if ((char)c == 'c') { break; } } } return 0;}/** @function detectAndDisplay */void detectAndDisplay(Mat frame){ std::vector<Rect> bodies; Mat frame_gray; cvtColor(frame, frame_gray, CV_BGR2GRAY); equalizeHist(frame_gray, frame_gray); //-- Detect faces upper_body_cascade.detectMultiScale(frame_gray, bodies, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30)); for (size_t i = 0; i < bodies.size(); i++) { rectangle(frame, bodies[i], Scalar(255, 0, 255)); } //-- Show what you got imshow(window_name, frame);} 这篇关于使用OpenCV检测上半身部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 14:42