{"id":810,"date":"2012-10-22T23:32:07","date_gmt":"2012-10-22T15:32:07","guid":{"rendered":"http:\/\/www.youthtribe.com\/?p=810"},"modified":"2012-10-22T23:32:07","modified_gmt":"2012-10-22T15:32:07","slug":"%e5%b0%86%e5%9b%be%e5%83%8f%e8%bf%9b%e8%a1%8c%e4%ba%8c%e5%80%bc%e5%8c%96%e5%a4%84%e7%90%86%e7%9a%84c%e7%a8%8b%e5%ba%8f%e6%ba%90%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"http:\/\/www.youthtribe.com\/archives\/810","title":{"rendered":"\u5c06\u56fe\u50cf\u8fdb\u884c\u4e8c\u503c\u5316\u5904\u7406\u7684C++\u7a0b\u5e8f\u6e90\u4ee3\u7801"},"content":{"rendered":"
\u6211\u6d4b\u8bd5\u8fc7\u4e86\uff0c\u53ef\u7528\uff01<\/p>\n
#include “cv.h”‘
\n#include “cxcore.h”
\n#include “highgui.h”
\n#include <iostream>
\nusing namespace std;
\nint main ()
\n{
\n\u00a0\u00a0\u00a0 IplImage* img = cvLoadImage(“asdf.jpg”,-1);
\n\u00a0\u00a0\u00a0 IplImage* biimg = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
\n\u00a0\u00a0\u00a0 CvScalar s;
\n\u00a0\u00a0\u00a0 int sum=0;
\n\u00a0\u00a0\u00a0 for (int i=0;i<img->height;i++)
\n\u00a0\u00a0\u00a0 {
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for (int j=0;j<img->width;j++)
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 s =\u00a0 cvGet2D(img,i,j);
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/cout<<s.val[0]<<” “<<s.val[1]<<” “<<s.val[2]<<endl;
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sum = (s.val[0]+s.val[1]+s.val[2])\/3;
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (sum > 128)
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 s.val[0]=s.val[1]=s.val[2]=255;
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 cvSet2D(img,i,j,s);
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 s.val[0]=s.val[1]=s.val[2]=0;
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 cvSet2D(img,i,j,s);<\/p>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }
\n\u00a0\u00a0\u00a0 }
\n\u00a0\u00a0\u00a0 cvCopy(img,biimg);
\n\u00a0\u00a0\u00a0 cvSaveImage(“combibi.JPG”,biimg);
\n\u00a0\u00a0\u00a0 cvNamedWindow(“imagebinary”);
\n\u00a0\u00a0\u00a0 cvShowImage(“imagebinary”,biimg);
\n\u00a0\u00a0\u00a0 cvWaitKey(0);
\n\u00a0\u00a0\u00a0 cvDestroyWindow(“imagebinary”);
\n\u00a0\u00a0\u00a0 cvReleaseImage(&img);
\n\u00a0\u00a0\u00a0 cvReleaseImage(&biimg);
\n}<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"\u6211\u6d4b\u8bd5\u8fc7\u4e86\uff0c\u53ef\u7528\uff01 #include “cv.h”‘ #include “cxcore.h” #include “highgui.h” #include <iostream> using namespace std; int main () { \u00a0\u00a0\u00a0 IplImage* img = cvLoadImage(“asdf.jpg”,-1); \u00a0\u00a0\u00a0 IplImage* biimg = cvCreateImage(cvGetSize(img),img->depth,img-<\/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\/810"}],"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=810"}],"version-history":[{"count":2,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/810\/revisions"}],"predecessor-version":[{"id":812,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/810\/revisions\/812"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=810"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}