{"id":902,"date":"2013-06-08T21:50:02","date_gmt":"2013-06-08T13:50:02","guid":{"rendered":"http:\/\/www.youthtribe.com\/?p=902"},"modified":"2013-10-23T20:59:25","modified_gmt":"2013-10-23T12:59:25","slug":"opencv-%e4%b9%8b%e4%ba%8c%e5%80%bc%e5%8c%96%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"http:\/\/www.youthtribe.com\/archives\/902","title":{"rendered":"opencv \u4e4b\u4e8c\u503c\u5316\u56fe\u7247"},"content":{"rendered":"

opencv \u4e4b\u4e8c\u503c\u5316\u56fe\u7247
\n
\n#include \"cv.h\"'
\n#include \"cxcore.h\"
\n#include \"highgui.h\"
\n#include
\nusing namespace std;
\n\/* way 1
\nint main ()
\n{
\nIplImage* img = cvLoadImage(\"asdf.jpg\",-1);
\nIplImage* biimg = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
\nCvScalar s;
\nint sum=0;
\nfor (int i=0;iheight;i++)
\n{
\nfor (int j=0;jwidth;j++)
\n{
\ns = cvGet2D(img,i,j);
\n\/\/cout< 128)
\n{
\ns.val[0]=s.val[1]=s.val[2]=255;
\ncvSet2D(img,i,j,s);
\n}
\nelse
\n{
\ns.val[0]=s.val[1]=s.val[2]=0;
\ncvSet2D(img,i,j,s);<\/code><\/p>\n

}
\n}
\n}
\ncvCopy(img,biimg);
\ncvSaveImage(“combibi.JPG”,biimg);
\ncvNamedWindow(“imagebinary”);
\ncvShowImage(“imagebinary”,biimg);
\ncvWaitKey(0);
\ncvDestroyWindow(“imagebinary”);
\ncvReleaseImage(&img);
\ncvReleaseImage(&biimg);
\n}
\n*\/
\n\/\/way 2
\nint main ()
\n{
\nIplImage* img = cvLoadImage(“asdf.jpg”,-1);
\nIplImage* binimg = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
\ncvThreshold(img,binimg,120,10,CV_THRESH_BINARY);\/\/\u8fd9\u662f\u6307\u5b9a\u9608\u503c\u4e86\uff0c\u4e5f\u53ef\u4ee5\u7528\u81ea\u9002\u5e94\u9608\u503c\u7684\u51fd\u6570\uff0ccvadaptivethreshold
\n\/\/cvCopy(img,binimg);
\ncvSaveImage(“combibi.JPG”,binimg);
\ncvNamedWindow(“imagebinary”);
\ncvShowImage(“imagebinary”,binimg);
\ncvWaitKey(0);
\ncvDestroyWindow(“imagebinary”);
\ncvReleaseImage(&img);
\ncvReleaseImage(&binimg);
\n}
\n\/* \/\/way 2 \u81ea\u9002\u5e94\u9608\u503c
\nint main ()
\n{
\nIplImage* img = cvLoadImage(“asdf.jpg”,-1);
\nIplImage* biimg = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
\nCvScalar s;
\nint sum=0;
\nfor (int i=0;iheight;i++)
\n{
\nfor (int j=0;jwidth;j++)
\n{
\ns = cvGet2D(img,i,j);
\n\/\/cout< 128)
\n{
\ns.val[0]=s.val[1]=s.val[2]=255;
\ncvSet2D(img,i,j,s);
\n}
\nelse
\n{
\ns.val[0]=s.val[1]=s.val[2]=0;
\ncvSet2D(img,i,j,s);<\/p>\n

}
\n}
\n}
\ncvCopy(img,biimg);
\ncvSaveImage(“combibi.JPG”,biimg);
\ncvNamedWindow(“imagebinary”);
\ncvShowImage(“imagebinary”,biimg);
\ncvWaitKey(0);
\ncvDestroyWindow(“imagebinary”);
\ncvReleaseImage(&img);
\ncvReleaseImage(&biimg);
\n}
\n*\/<\/p>\n","protected":false},"excerpt":{"rendered":"

opencv \u4e4b\u4e8c\u503c\u5316\u56fe\u7247 #include “cv.h”‘ #include “cxcore.h” #include “highgui.h” #include using namespace std; \/* way 1 int main () { IplImage* img = cvLoadImage(“asdf.jpg”,-1); IplImage* biimg = cvCreateImage(cvGetSize(img),img->depth,img->nChannels); CvScalar s; int sum=0; for (int i=0;iheight;i++) {<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,9],"tags":[],"_links":{"self":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/902"}],"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=902"}],"version-history":[{"count":3,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/902\/revisions"}],"predecessor-version":[{"id":904,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/902\/revisions\/904"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=902"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}