2010年9月29日 星期三

Homework 3





































#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include "stdio.h"

#define alpha 2
#define x1 0
#define y1 0

int main()
{
CvCapture *capture;
IplImage *pImg;
IplImage *bImg;
IplImage *gImg;
IplImage *rImg;
IplImage *logoImg;
IplImage *mergeImg;
capture=cvCreateCameraCapture( 0 );
cvNamedWindow("Webcam",1);
cvNamedWindow("Webcam2",1);
cvNamedWindow("Webcam3",1);
cvNamedWindow("Webcam4",1);
cvNamedWindow("Webcam5",1);
logoImg=cvLoadImage("logo.jpg");
pImg = cvQueryFrame(capture);
bImg = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 3);
gImg = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 3);
rImg = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 3);
mergeImg = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 3);
while(1)
{
// Get blue pixels
for (int y=0; yheight; y++) {
uchar* ptr1=(uchar*) (pImg->imageData +y*pImg->widthStep);
uchar* ptr2=(uchar*) (bImg->imageData +y*bImg->widthStep);
for (int x=0; xwidth; x++) {
ptr2[3*x]=ptr1[3*x];
ptr2[3*x+1]=0;
ptr2[3*x+2]=0;
}
}

// Get green pixels
for (int y=0; yheight; y++) {
uchar* ptr1=(uchar*) (pImg->imageData +y*pImg->widthStep);
uchar* ptr2=(uchar*) (gImg->imageData +y*gImg->widthStep);
for (int x=0; xwidth; x++) {
ptr2[3*x]=0;
ptr2[3*x+1]=ptr1[3*x+1];
ptr2[3*x+2]=0;
}
}

// Get red pixels
for (int y=0; yheight; y++) {
uchar* ptr1=(uchar*) (pImg->imageData +y*pImg->widthStep);
uchar* ptr2=(uchar*) (rImg->imageData +y*rImg->widthStep);
for (int x=0; xwidth; x++) {
ptr2[3*x]=0;
ptr2[3*x+1]=0;
ptr2[3*x+2]=ptr1[3*x];
}
}


if( (logoImg->height + y1) <>height) {
mergeImg=cvCloneImage(pImg);
for (int y=0; yheight; y++) {
uchar* ptr1=(uchar*) (logoImg->imageData +y*logoImg->widthStep);
uchar* ptr2=(uchar*) (mergeImg->imageData +(y+y1)*mergeImg->widthStep);
for (int x=0; xwidth; x++) {
ptr2[3*(x+x1)]=alpha*ptr1[3*(x+x1)] + (1-alpha)*ptr2[3*(x+x1)];
ptr2[3*(x+x1)+1]=alpha*ptr1[3*(x+x1)+1] + (1-alpha)*ptr2[3*(x+x1)+1];
ptr2[3*(x+x1)+2]=alpha*ptr1[3*(x+x1)+2] + (1-alpha)*ptr2[3*(x+x1)+2];
}
}
}
pImg = cvQueryFrame(capture);

cvShowImage("Webcam", pImg);
cvFlip(bImg,bImg,0);
cvShowImage("Webcam2", bImg);
cvFlip(gImg,gImg,1);
cvShowImage("Webcam3", gImg);
cvFlip(rImg,rImg,0);
cvShowImage("Webcam4", rImg);
cvFlip(mergeImg,mergeImg,1);
cvShowImage("Webcam5", mergeImg);
cvWaitKey(20);
}
cvReleaseCapture(&capture);
cvDestroyWindow("Webcam");
cvDestroyWindow("Webcam2");
cvDestroyWindow("Webcam3");
cvDestroyWindow("Webcam4");
cvDestroyWindow("Webcam5");
}

沒有留言:

張貼留言