1.最喜歡的作業?
期中專案是我最喜歡的作業,大學四年很少有可以實際操作電路板的作業,這一次的作業結合電腦和硬體,而我們這組作出了遙控船,而且可以實際的在水上移動,唯獨沒辦法無線遙控是要繼續改進的。
2.你在課程中學到什麼?
學到了整合軟硬體的能力,以及團隊合作,還有多媒體相關基礎,像是學會控制像素點,尋找人臉,藉由這些工具,做到自己想要的結果,期末專案更是能自己發揮,做出好玩的互動遊戲,雖然途中遇到很多困難,不過在團隊的努力下都能迎刃而解。
3.上完課的改變?
學會做出一個多媒體專案,結合自己程式寫作的能力,另外包合了基礎電路能力,做出屬於自己的應用程式,總之互動電子蠻好玩的!
2013年6月9日 星期日
水果盤
int val;
int val2;
int ledPin;
int temp;
int Tone;
int speakerOut = 4;
void setup()
{
Serial.begin(9600);
pinMode(speakerOut, OUTPUT);
for(ledPin=10;ledPin<=13;ledPin++){
pinMode(ledPin, OUTPUT);
}
}
void loop()
{
Tone = 2028;
int LED_i;
Serial.print(val);
//delay(150);
val = analogRead(0);
val2 = 1000;
for(LED_i=10;LED_i<=13;LED_i++)
{
val2=analogRead(2);
Serial.print(val2);
if(val2<60){
digitalWrite(LED_i, HIGH);
if(LED_i==11){
tone(4,2080,1000);
/* digitalWrite(speakerOut, HIGH);
delayMicroseconds(Tone / 2);
delay(1000);
digitalWrite(speakerOut , LOW);
delayMicroseconds(Tone / 2);
*/
}
delay(3000);
}
digitalWrite(LED_i, HIGH);
delay(val);
digitalWrite(LED_i, LOW);
}
}
2013年5月29日 星期三
期末專案
#include<cv.h>
#include<iostream>
#include<highgui.h>
#include<stdio.h>
#define alpha 1
#define x1 0
#define y1 0
using namespace std;
int main()
{
CvCapture *capture;
IplImage* pImg = NULL;
IplImage* pImg2 = NULL;
IplImage* grey = NULL;
IplImage* pImgcr = NULL;
IplImage* logoImg = NULL;
IplImage* logoImg1 = NULL;
IplImage* logoImg2 = NULL;
IplImage* logoImg3 = NULL;
IplImage* logoImg4 = NULL;
int score=0;
int scorex;
int scorey;
//cout<<"1";
while(true){
capture=cvCreateCameraCapture( 0 );
pImg=cvQueryFrame(capture);
logoImg=cvLoadImage("006.jpg");
logoImg1=cvLoadImage("002.jpg");
logoImg2=cvLoadImage("004.jpg");
logoImg3=cvLoadImage("008.jpg");
logoImg4=cvLoadImage("exit.jpg");
float mouseX=0;
float mouseY=0;
float redPixelNumber=0;
float redPixelX=0;
float redPixelY=0;
grey = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 1);
pImgcr = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 3);
cvCvtColor(pImg, pImgcr, CV_BGR2YCrCb);
cvInRangeS(pImgcr, cvScalar(0,137,77), cvScalar(256,177,127),grey);
for (int y=0; y<grey->height; y++) {
uchar* ptr1=(uchar*) (grey->imageData +y*grey->widthStep);
//uchar* ptr1=(uchar*) (pImg->imageData +y*pImg->widthStep);
for (int x=0; x<grey->width; x++) {
if(ptr1[x]==255){
redPixelNumber++;
redPixelX+=x;
redPixelY+=y;
}
}
if (redPixelNumber>0) {
mouseX=redPixelX/redPixelNumber;
mouseY=redPixelY/redPixelNumber;
}
}
int mousex1=mouseX-60;
int mousey1=mouseY-60;
int scorex=mouseX;
int scorey=mouseY;
if( (logoImg->height + mousey1) < pImg->height) {
for (int y=0; y<logoImg->height; y++) {
uchar* ptr1=(uchar*) (logoImg->imageData +y*logoImg->widthStep);
uchar* ptr2=(uchar*) (pImg->imageData +((mousey1+y))*pImg->widthStep);
for (int x=0; x<logoImg->width; x++) {
if(ptr1[3*(x)]<255&& ptr1[3*(x)+1]<255&& ptr1[3*(x)+2]<255){
ptr2[3*(x+mousex1)]=ptr1[3*(x)];
ptr2[3*(x+mousex1)+1]=ptr1[3*(x)+1];
ptr2[3*(x+mousex1)+2]=ptr1[3*(x)+2];
}
}
}
}
if(scorex <pImg->width/3&&scorey <pImg->height/2){
score+=10;
cout<<"伊凡萬科死了"<<" "<<"得分"<<score<<endl;
cvWaitKey(100);
//Sleep(100);
}
if(scorex >pImg->width/3&&scorex <(pImg->width/3)*2&&scorey<pImg->height/2){
score+=30;
cout<<"滿大人死了"<<" "<<"得分"<<score<<endl;
cvWaitKey(100);
//Sleep(100);
}
if(scorex>(pImg->width/3)*2&&scorey <pImg->height/2){
score+=50;
cout<<"火焰人死了"<<" "<<"得分"<<score<<endl;
cvWaitKey(100);
//Sleep(100);
}
//---------------------------------------------------------------------------------
if( (logoImg1->height + y1) < pImg->height) {
for (int y=0; y<logoImg1->height; y++) {
uchar* ptr1=(uchar*) (logoImg1->imageData +y*logoImg1->widthStep);
uchar* ptr2=(uchar*) (pImg->imageData+150 +(75+y)*pImg->widthStep);
for (int x=0; x<logoImg1->width; x++) {
if(ptr1[3*(x)]<250&& ptr1[3*(x)+1]<250&& ptr1[3*(x)+2]<250){
ptr2[3*(x+x1)]=ptr1[3*(x+x1)];
ptr2[3*(x+x1)+1]=ptr1[3*(x+x1)+1];
ptr2[3*(x+x1)+2]=ptr1[3*(x+x1)+2];
}
}
}
}
//---------------------------------------------------------------------------------
if( (logoImg2->height + y1) < pImg->height) {
for (int y=0; y<logoImg2->height; y++) {
uchar* ptr1=(uchar*) (logoImg2->imageData +y*logoImg2->widthStep);
uchar* ptr2=(uchar*) (pImg->imageData +810+(y+75)*pImg->widthStep);
for (int x=0;x<logoImg2->width; x++) {
if(ptr1[3*(x)]<250&& ptr1[3*(x)+1]<250&& ptr1[3*(x)+2]<250){
ptr2[3*(x+x1)]=ptr1[3*(x+x1)];
ptr2[3*(x+x1)+1]=ptr1[3*(x+x1)+1];
ptr2[3*(x+x1)+2]=ptr1[3*(x+x1)+2];
}
}
}
}
//---------------------------------------------------------------------------------
if( (logoImg3->height + y1) < pImg->height) {
for (int y=0; y<logoImg3->height; y++) {
uchar* ptr1=(uchar*) (logoImg3->imageData +y*logoImg3->widthStep);
uchar* ptr2=(uchar*) (pImg->imageData +1377+(y+75)*pImg->widthStep);
for (int x=0;x<logoImg3->width; x++) {
if(ptr1[3*(x)]<250&& ptr1[3*(x)+1]<250&& ptr1[3*(x)+2]<250){
ptr2[3*(x+x1)]=ptr1[3*(x+x1)];
ptr2[3*(x+x1)+1]=ptr1[3*(x+x1)+1];
ptr2[3*(x+x1)+2]=ptr1[3*(x+x1)+2];
}
}
}
}
//---------------------------------------------------------------------------------
if( (logoImg4->height + y1) < pImg->height) {
for (int y=0; y<logoImg4->height; y++) {
uchar* ptr1=(uchar*) (logoImg4->imageData +y*logoImg4->widthStep);
uchar* ptr2=(uchar*) (pImg->imageData +1620+(y+380)*pImg->widthStep);
for (int x=0;x<logoImg4->width; x++) {
if(ptr1[3*(x)]<250&& ptr1[3*(x)+1]<250&& ptr1[3*(x)+2]<250){
ptr2[3*(x)]=ptr1[3*(x+x1)];
ptr2[3*(x)+1]=ptr1[3*(x+x1)+1];
ptr2[3*(x)+2]=ptr1[3*(x+x1)+2];
}
}
}
}
//---------------------------------------------------------------------------------
// mousex1
// mousey1
//cvLine(pImg,cvPoint(mouseX-10,mouseY),cvPoint(mouseX+10,mouseY),CV_RGB(255,0,0),12,8,0);
//cvLine(pImg,cvPoint(mouseX,mouseY-10),cvPoint(mouseX,mouseY+10),CV_RGB(255,0,0),12,8,0);
cvLine(pImg,cvPoint(pImg->width/3,0),cvPoint(pImg->width/3,pImg->height),CV_RGB(255,0,0),12,8,0);
cvLine(pImg,cvPoint((pImg->width/3)*2,0),cvPoint((pImg->width/3)*2,pImg->height),CV_RGB(255,0,0),12,8,0);
cvShowImage("webcam",pImg);
char key = cvWaitKey(33);
// if(key == 27)break;
//if(key == 27)break;
if(scorex >(pImg->width/5)*4&&scorey>(pImg->height/5)*4)break;
}
}
HW4-變色
2013年5月26日 星期日
98360782_田偉安_考試心得
考試題目:
將畫面從中切成兩半,並在中間切割處畫上紅線,同時兩邊分別各有一頂不同皇冠,當頭移至右邊時,戴上右邊黃冠,左邊時,戴上左邊皇冠。
考試結果:
大致上全部都有做出來,但是唯獨出現一個小敗筆,就是皇冠無法正確的戴上頭頂,會卡在額頭上,所幸在考完試後,與同學討論,發現自己的錯誤地方,也順利解決了問題。
錯誤地方為紅色標示處:
將畫面從中切成兩半,並在中間切割處畫上紅線,同時兩邊分別各有一頂不同皇冠,當頭移至右邊時,戴上右邊黃冠,左邊時,戴上左邊皇冠。
考試結果:
大致上全部都有做出來,但是唯獨出現一個小敗筆,就是皇冠無法正確的戴上頭頂,會卡在額頭上,所幸在考完試後,與同學討論,發現自己的錯誤地方,也順利解決了問題。
錯誤地方為紅色標示處:
int mousex1=mouseX;
int mousey1=mouseY;
if(mousex1<pImg->width/2){
if( (logoImg->height + mousey1) < pImg->height) {
for (int y=0; y<logoImg->height; y++) {
uchar* ptr1=(uchar*) (logoImg->imageData +y*logoImg->widthStep);
uchar* ptr2=(uchar*) (pImg->imageData +(mousey1+y)*pImg->widthStep);
for (int x=0; x<logoImg->width; x++) {
if(ptr1[3*(x)]<250&& ptr1[3*(x)+1]<250&& ptr1[3*(x)+2]<250){
ptr2[3*(x+mousex1)]=ptr1[3*(x) ];
ptr2[3*(x+mousex1)+1]=ptr1[3*( x)+1];
ptr2[3*(x+mousex1)+2]=ptr1[3*( x)+2];
}
}
}
}
}
else{
//int mousex2=mouseX+640;
//int mousey2=mouseY+640;
if( (logoImg2->height + mousey1) < pImg->height) {
for (int y=0; y<logoImg2->height; y++) {
uchar* ptr1=(uchar*) (logoImg2->imageData +y*logoImg2->widthStep);
uchar* ptr2=(uchar*) (pImg->imageData +(mousey1+y)*pImg->widthStep);
for (int x=0; x<logoImg2->width; x++) {
if(ptr1[3*(x)]<250&& ptr1[3*(x)+1]<250&& ptr1[3*(x)+2]<250){
ptr2[3*(x+mousex1)]=ptr1[3*(x) ];
ptr2[3*(x+mousex1)+1]=ptr1[3*( x)+1];
ptr2[3*(x+mousex1)+2]=ptr1[3*( x)+2];
}
}
}
}
}
經與同學討論後,發現只是自己對座標的認知錯誤,導致參數設定有問題,自己原本所想的剛好與正確的方式相反,所以反而越改越下面,不過在同學的幫忙下,順利地調整成正確的顯示方式。
2013年5月6日 星期一
互動電子-作業三-相框
主要程式碼:
if( (logoImg->height + y1) < mergeImg->height) {
mergeImg=cvCloneImage(pImg);
for (int y=0; y<logoImg->height; y++) {
uchar* ptr1=(uchar*) (logoImg->imageData +y*logoImg->widthStep);
uchar* ptr2=(uchar*) (mergeImg->imageData +(y+y1)*mergeImg->widthStep);
for (int x=0; x<logoImg->width; x++) {
if(ptr1[3*(x)]<230&& ptr1[3*(x)+1]<230&& ptr1[3*(x)+2]<230){
ptr2[3*(x+x1)]=ptr1[3*(x+x1)];
ptr2[3*(x+x1)+1]=ptr1[3*(x+x1)+1];
ptr2[3*(x+x1)+2]=ptr1[3*(x+x1)+2];
}
}
}
}
2013年4月22日 星期一
互動電子-hw1-自畫像
重點程式碼:
pImg2 = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 3);
gray = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 1);
bw = cvCreateImage(cvSize(pImg->width,pImg->height), IPL_DEPTH_8U, 1);
pCannyImg = cvCreateImage(cvGetSize(pImg), IPL_DEPTH_8U, 1);
cvNamedWindow("src", 1);
cvNamedWindow("gray",1);
while(1)
{
pImg=cvQueryFrame(capture);
cvResize(pImg,dst,CV_INTER_NN);
cvCvtColor(pImg, gray, CV_BGR2GRAY);
cvThreshold( gray, bw, 130, 255, CV_THRESH_BINARY );
cvThreshold( pImg, pImg2, 127, 255, CV_THRESH_BINARY );
cvCanny(gray, pCannyImg, 50, 150, 3);
訂閱:
文章 (Atom)










