{"id":898,"date":"2013-06-08T21:23:52","date_gmt":"2013-06-08T13:23:52","guid":{"rendered":"http:\/\/www.youthtribe.com\/?p=898"},"modified":"2013-06-08T21:23:52","modified_gmt":"2013-06-08T13:23:52","slug":"opencv%e4%b9%8b%e8%be%b9%e7%bc%98%e6%a3%80%e6%b5%8b","status":"publish","type":"post","link":"http:\/\/www.youthtribe.com\/archives\/898","title":{"rendered":"opencv\u4e4b\u8fb9\u7f18\u68c0\u6d4b"},"content":{"rendered":"

opencv\u4e4b\u8fb9\u7f18\u68c0\u6d4b<\/p>\n

\/\/ \u8fb9\u7f18\u68c0\u6d4b-canddy.cpp : \u5b9a\u4e49\u63a7\u5236\u53f0\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u3002<\/p>\n

\/\/<\/p>\n

 <\/p>\n

#include “stdafx.h”<\/p>\n

 <\/p>\n

 <\/p>\n

\/**************************************************<\/p>\n

* C++ Canny\uff1aCanny\u8fb9\u7f18\u68c0\u6d4b<\/p>\n

**************************************************\/<\/p>\n

 <\/p>\n

\/***********************************************************************<\/p>\n

* OpenCV example<\/p>\n

* By Min Qi February 26, 2012, Indianapolis, IN<\/p>\n

***********************************************************************\/<\/p>\n

 <\/p>\n

#include <opencv2\/opencv.hpp><\/p>\n

#include <opencv\/cv.h><\/p>\n

 <\/p>\n

using namespace cv;<\/p>\n

\/\/#include “opencv2\\highgui\\highgui.hpp”<\/p>\n

 <\/p>\n

using namespace cv;<\/p>\n

using namespace std;<\/p>\n

 <\/p>\n

int edgeThresh = 1;<\/p>\n

 <\/p>\n

\/\/ \u58f0\u660e \u539f\u59cb\u56fe\u7247\uff0c\u7070\u5ea6\u56fe\u7247\uff0c\u548c canny\u8fb9\u7f18\u56fe\u7247<\/p>\n

Mat image, cedge;<\/p>\n

Mat gray, edge;<\/p>\n

 <\/p>\n

void onTrackbar(int, void*)<\/p>\n

{<\/p>\n

\/\/blur \u7070\u5ea6\u56fe\u7247<\/p>\n

blur(gray, edge, Size(3,3));<\/p>\n

 <\/p>\n

\/\/ Canny \u8fb9\u7f18\u68c0\u6d4b<\/p>\n

Canny(gray,edge, edgeThresh, edgeThresh*3, 3);<\/p>\n

 <\/p>\n

\/\/\u5168\u90e8\u8bbe\u4e3a0<\/p>\n

cedge = Scalar::all(0);<\/p>\n

 <\/p>\n

\/\/\u62f7\u8d1d\u8fb9\u7f18\u7684\u8c61\u7d20\u70b9<\/p>\n

image.copyTo(cedge, edge);<\/p>\n

 <\/p>\n

imshow(“Edge map”, edge);<\/p>\n

 <\/p>\n

}<\/p>\n

 <\/p>\n

int main(int argc, char** argv)<\/p>\n

{<\/p>\n

 <\/p>\n

 <\/p>\n

\/\/ \u8f7d\u5165\u56fe\u7247<\/p>\n

\/\/image = imread(argv[1], 1);<\/p>\n

image = imread(“test.jpg”, 1);<\/p>\n

 <\/p>\n

\/\/ \u5224\u65ad\u8f7d\u5165\u56fe\u7247\u662f\u5426\u6210\u529f<\/p>\n

if(image.empty())<\/p>\n

{<\/p>\n

printf(“miss the image file: %d \\n”, argv[1]);<\/p>\n

return -1;<\/p>\n

}<\/p>\n

 <\/p>\n

\/\/ \u751f\u6210\u7070\u5ea6\u56fe\u7247\uff0c\u56e0\u4e3a\u53ea\u6709\u7070\u5ea6\u56fe\u7247\u624d\u80fd\u751f\u6210\u8fb9\u7f18\u56fe\u7247<\/p>\n

cedge.create(image.size(), image.type());<\/p>\n

cvtColor(image,gray, CV_BGR2GRAY);<\/p>\n

 <\/p>\n

\/\/\u65b0\u5efa\u4e00\u4e2a\u7a97\u53e3<\/p>\n

namedWindow(“Edge map”, 1);<\/p>\n

 <\/p>\n

\/\/ \u751f\u6210\u4e00\u4e2a\u8fdb\u5ea6\u6761\u6765\u63a7\u5236\u8fb9\u7f18\u68c0\u6d4b<\/p>\n

createTrackbar(“Canny Threshold”, “Edge map”, &edgeThresh, 100, onTrackbar);<\/p>\n

 <\/p>\n

\/\/\u521d\u59cb\u5316\u56fe\u50cf<\/p>\n

onTrackbar(0,0);<\/p>\n

 <\/p>\n

waitKey(0);<\/p>\n

 <\/p>\n

return 0;<\/p>\n

}<\/p>\n

 <\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"

opencv\u4e4b\u8fb9\u7f18\u68c0\u6d4b \/\/ \u8fb9\u7f18\u68c0\u6d4b-canddy.cpp : \u5b9a\u4e49\u63a7\u5236\u53f0\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u70b9\u3002 \/\/   #include “stdafx.h”     \/************************************************** * C++ Canny\uff1aCanny\u8fb9\u7f18\u68c0\u6d4b **************************************************\/   \/**************************************************************<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,150],"tags":[153],"_links":{"self":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/898"}],"collection":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/comments?post=898"}],"version-history":[{"count":3,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/898\/revisions"}],"predecessor-version":[{"id":901,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/898\/revisions\/901"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=898"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}