顯示具有 Brian Houng 標籤的文章。 顯示所有文章
顯示具有 Brian Houng 標籤的文章。 顯示所有文章

2010年10月20日 星期三

Homework 4-4: Tracking Watermelon


















This practice was very interesting as it allowed me to track a specific color in the webcam. In this case, I tracked the color blue, with 0,0,255. And used a marker to track the coordinates in the camera. Then I load the watermelon logo and set the coordinates to the pointer. This practice was very challenging to implement because we had to connect the logo and create new variables to create a new arithmetic that allow for a tracking coordination.

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");
}

2010年9月15日 星期三

CVFlip 96470026-BrianHoung


This assignment is very interesting as it helps me create an interactive application while being able to see if the program works without any bugs very easily. The most challenging part of the program was being able to create four webcam images and flipping them in the correct position. Now I know that the cvFlip command is supposed to flip the image of the last webcam image that was created, instead of relative to the first one.

HW1-96470026