上禮拜看到老師做出來的成品,可以拿一顆球畫你想要圖形,這裡禮拜終於學到了一點點,畫面分割變顏色,變數的條件改一改就好,不過我覺得厲害的是可以抓取顏色,但是抓取的顏色是裡面定死的,不過門檻值也要設好,不然整個畫面很搞笑,畫圖超好玩不過我不知道要畫啥,所以頭跟身體晃一晃就變這樣,今天怎麼這麼剛好,全身黑。
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include "stdio.h"
#define alpha 0.5
int main( int argc, char** argv )
{
//聲明 IplImage
IplImage* pImg = NULL;
IplImage* blue = NULL;
IplImage* green = NULL;
IplImage* red = NULL;
IplImage* logoImg = NULL;
IplImage* mergeImg = NULL;
CvCapture *capture;
int x1 = 0;
int y1 = 0;
capture=cvCreateCameraCapture( 0 );
logoImg=cvLoadImage("logo.jpg");
cvFlip(logoImg,0,0);
//創建視窗
cvNamedWindow("src", 1);
cvNamedWindow("blue", 1);
cvNamedWindow("green", 1);
cvNamedWindow("red", 1);
cvNamedWindow("Image with Logo", 1);
while(1)
{
x1+=10;
pImg=cvQueryFrame(capture);
//為圖像申請空間
cvFlip(pImg,0,0);
blue = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 3);
green = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 3);
red = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 3);
mergeImg = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 3);
for (int y=0; y
uchar* ptr1=(uchar*) (pImg->imageData +y*pImg->widthStep);
uchar* ptr2=(uchar*) (blue->imageData +y*blue->widthStep);
for (int x=0; x
ptr2[3*x]=ptr1[3*x];
ptr2[3*x+1]=0;
ptr2[3*x+2]=0;
}
ptr2=(uchar*) (green->imageData +y*green->widthStep);
for (int x=0; x
ptr2[3*x]=0;
ptr2[3*x+1]=ptr1[3*x+1];
ptr2[3*x+2]=0;
}
ptr2=(uchar*) (red->imageData +y*red->widthStep);
for (int x=0; x
ptr2[3*x]=0;
ptr2[3*x+1]=0;
ptr2[3*x+2]=ptr1[3*x];
}
}
// 顯示圖像
cvFlip(pImg,0,0);
if( (logoImg->height + y1) <>height) {
mergeImg=cvCloneImage(pImg);
for (int y=0; y
uchar* ptr3=(uchar*) (logoImg->imageData +y*logoImg->widthStep);
uchar* ptr4=(uchar*) (mergeImg->imageData +(y+y1)*mergeImg->widthStep);
for (int x=0; x
ptr4[3*(x+x1)]=alpha*ptr3[3*(x)] + (1-alpha)*ptr4[3*(x+x1)];
ptr4[3*(x+x1)+1]=alpha*ptr3[3*(x)+1] + (1-alpha)*ptr4[3*(x+x1)+1];
ptr4[3*(x+x1)+2]=alpha*ptr3[3*(x)+2] + (1-alpha)*ptr4[3*(x+x1)+2];
}
}
}
cvShowImage( "src", pImg );
cvShowImage( "blue", blue );
cvShowImage( "green", green );
cvShowImage( "red", red );
cvShowImage( "Image with Logo", mergeImg );
cvWaitKey(2); //等待按鍵
}
//釋放圖像
cvReleaseImage( &pImg );
cvReleaseImage( &blue );
cvReleaseImage( &green );
cvReleaseImage( &red );
cvReleaseImage( &mergeImg );
//銷毀視窗
cvDestroyWindow( "src" );
cvDestroyWindow( "blue" );
cvDestroyWindow( "green" );
cvDestroyWindow( "red" );
cvDestroyWindow( "Image with Logo" );
}
沒有留言:
張貼留言