{"id":702,"date":"2011-12-04T21:49:05","date_gmt":"2011-12-04T13:49:05","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=702"},"modified":"2011-12-04T21:50:51","modified_gmt":"2011-12-04T13:50:51","slug":"people-detection-sample-from-opencv","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2011\/12\/04\/people-detection-sample-from-opencv\/","title":{"rendered":"People Detection Sample from OpenCV"},"content":{"rendered":"<p>There are a number of requests of the code I adopt the OpenCV people detection sample. Here it is.<\/p>\n<pre lang=\"cpp\">\r\n#include <opencv2\/opencv.hpp>\r\n\r\nusing namespace cv;\r\n\r\nint main (int argc, const char * argv[])\r\n{\r\n    VideoCapture cap(0);\r\n    cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);\r\n    cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);\r\n    \r\n    if (!cap.isOpened())\r\n        return -1;\r\n    \r\n    Mat img;\r\n    namedWindow(\"opencv\", CV_WINDOW_AUTOSIZE);\r\n    HOGDescriptor hog;\r\n    hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());\r\n    \r\n    while (true)\r\n    {\r\n        cap >> img;\r\n        if (img.empty())\r\n            continue;\r\n        \r\n        vector<Rect> found, found_filtered;\r\n        hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);\r\n        size_t i, j;\r\n        for (i=0; i<found.size(); i++) \r\n        {\r\n            Rect r = found[i];\r\n            for (j=0; j<found.size(); j++) \r\n                if (j!=i &#038;&#038; (r &#038; found[j]) == r)\r\n                    break;\r\n            if (j== found.size())\r\n                found_filtered.push_back(r);\r\n        }\r\n        \r\n        for (i=0; i<found_filtered.size(); i++) \r\n        {\r\n            Rect r = found_filtered[i];\r\n            r.x += cvRound(r.width*0.1);\r\n\t\t    r.width = cvRound(r.width*0.8);\r\n\t\t    r.y += cvRound(r.height*0.07);\r\n\t\t    r.height = cvRound(r.height*0.8);\r\n\t\t    rectangle(img, r.tl(), r.br(), Scalar(0,255,0), 3);        \r\n        }\r\n        \r\n        imshow(\"opencv\", img);\r\n        if (waitKey(10)>=0)\r\n            break;\r\n    }\r\n    return 0;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There are a number of requests of the code I adopt the OpenCV people detection sample. Here it is. #include using namespace cv; int main (int argc, const char * argv[]) { VideoCapture cap(0); cap.set(CV_CAP_PROP_FRAME_WIDTH, 320); cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240); if (!cap.isOpened()) return -1; Mat img; namedWindow(&#8220;opencv&#8221;, CV_WINDOW_AUTOSIZE); HOGDescriptor hog; hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector()); while (true) { cap >> img; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79],"tags":[3,16],"class_list":["post-702","post","type-post","status-publish","format-standard","hentry","category-software-2","tag-opencv","tag-people-detection"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/comments?post=702"}],"version-history":[{"count":2,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/702\/revisions"}],"predecessor-version":[{"id":704,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/702\/revisions\/704"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=702"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}