- 最後登錄
- 2023-5-11
- 在線時間
- 3 小時
- 註冊時間
- 2010-3-23
- 閱讀權限
- 20
- 精華
- 0
- UID
- 7801997
- 帖子
- 373
- 積分
- 254 點
- 潛水值
- 19561 米
| 我是使用 Dev-C++4.9.9.2的版本- #include <stdio.h>
- #include <cv.h>
- #include <highgui.h>
- #define alpha 0.9
- #define alphaf 0.8
- int Fishx[15];
- int Fishy[15];
- int tacox;
- int tacoy;
- int main()
- {
- CvCapture *capture;
- IplImage *frame,*grey,*mergeImg;
- IplImage* logoImg = NULL;
- IplImage* MouseImg1 = NULL;
- IplImage* win = NULL;
- IplImage* PicTaco =NULL;
- IplImage* black =NULL;
- IplImage* white =NULL;
- CvPoint TextPosition1,TextPosition2,TextPosition3,TextPosition4;
- double Scale;
- int Thickness;
- CvScalar Color;
- Scale=1;
- Thickness=1;
- CvFont Font1=cvFont(Scale,Thickness);
- Color=CV_RGB(0,0,255);
- TextPosition1=cvPoint(220,20);
- TextPosition2=cvPoint(280,20);
- TextPosition3=cvPoint(220,40);
- TextPosition4=cvPoint(280,40);
- logoImg=cvLoadImage("fish.PNG");
- //cvFlip(logoImg,logoImg,0);
- MouseImg1=cvLoadImage("t01.PNG");
- win=cvLoadImage("win.jpg");
- PicTaco = cvLoadImage("taco.jpg");
- black = cvLoadImage("black.jpg");
- white = cvLoadImage("background.jpg");
- //cvFlip(MouseImg1,MouseImg1,0);
- CvFont font;
- int MouseX=0;
- int MouseY=0;
- int Fish=15;
- int Grade=0;
- int direct=0;
- int taco=1;
- char final[3];
- char times[3];
- int count=0;
- capture=cvCreateCameraCapture( 0 );
- frame = cvQueryFrame(capture);
- mergeImg = cvQueryFrame(capture);
- grey = cvCreateImage(cvSize(frame->width,frame->height), IPL_DEPTH_8U, 1);
- cvNamedWindow("now",0);
- cvNamedWindow("trans",0);
- cvNamedWindow("Black",0);
- cvNamedWindow("DE",0);
- /*Random fish position*/
- for(int i=0;i<Fish;i++){
- Fishx[i]= rand() % (frame->width - logoImg->width - 2);
- Fishy[i]= rand() % (frame->height - logoImg->height - 2);
- }
- /*Random taco position*/
- tacox=rand() % (frame->width - logoImg->width - 2);
- tacoy=rand() % (frame->height - logoImg->height - 2);;
- int con=1;
- while(1)
- {
- white = cvLoadImage("background.jpg");
- mergeImg = white;
- cvPutText(mergeImg,"Grade",TextPosition1,&Font1,Color);
- cvShowImage("DE", mergeImg);
- if(Grade==15){
- cvShowImage("DE",win);
- }
- frame = cvQueryFrame(capture);
- //cvFlip(frame,frame,1);
- cvShowImage("now", frame);
- cvCvtColor(frame, frame, CV_BGR2YCrCb);
- cvShowImage("trans", frame);
- cvInRangeS(frame, cvScalar(0,137,77), cvScalar(256,177,127),grey);
- cvFlip(grey,grey,0);
- cvErode(grey,grey,0,5);
- cvDilate(grey,grey,0,5);
- cvShowImage("Black", grey);
- /*Regulate the Fish Position*/
- direct=Fish;
- for(int i=0;i<Fish;i++){
- if(Fishy[i]!=frame->height*2){
- if (i<(direct/3))
- Fishy[i] = ((Fishy[i] - 5) % (frame->height - logoImg->height + 20));
- else if(i<((2*direct)/3))
- Fishx[i] = ((Fishx[i] + 5) % (frame->width - logoImg->width - 2));
- else{
- Fishy[i] = ((Fishy[i] - 5) % (frame->height - logoImg->height + 20));
- Fishx[i] = ((Fishx[i] + 5) % (frame->width - logoImg->width - 2));
- }
- }
- if(Fishy[i]==(frame->height*2)){
- Fishy[i]+=0;
- Fishx[i]+=0;
- }
- else if ((Fishy[i] < 0) || (Fishy[i]>(frame->height)) || (Fishx[i] < 0) || (Fishx[i]>(frame->width))){
- Fishy[i] = rand() % (frame->height - logoImg->height - 2);
- Fishx[i] = rand() % (frame->width - logoImg->width - 2);
- }
- }
- /*Regulate the taco Position*/
- if(taco==1){
- if(tacoy!=frame->height*2){
- tacoy = ((tacoy - 5) % (frame->height - logoImg->height + 20));
- tacox = ((tacox + 5) % (frame->width - logoImg->width - 2));
- }
- if(tacoy==(frame->height*2)){
- tacoy+=0;
- tacox+=0;
- }
- else if ((tacoy < 0) || (tacoy>(frame->height)) || (tacox < 0) || (tacox>(frame->width))){
- tacoy = rand() % (frame->height - logoImg->height - 2);
- tacox = rand() % (frame->width - logoImg->width - 2);
- }
- }
- /*Show the Fish*/
- for(int i=0;i<Fish;i++){
- for (int y1=0; y1<logoImg->height; y1++) {
- uchar* ptr1=(uchar*) (logoImg->imageData +y1*logoImg->widthStep);
- uchar* ptr2=(uchar*) (mergeImg->imageData +(y1+Fishy[i])*mergeImg->widthStep);
- for (int x1=0; x1<logoImg->width; x1++) {
- ptr2[3*(x1+Fishx[i])]=alphaf*ptr1[3*(x1)] + (1-alphaf)*ptr2[3*(x1+Fishx[i])];
- ptr2[3*(x1+Fishx[i])+1]=alphaf*ptr1[3*(x1)+1] + (1-alphaf)*ptr2[3*(x1+Fishx[i])+1];
- ptr2[3*(x1+Fishx[i])+2]=alphaf*ptr1[3*(x1)+2] + (1-alphaf)*ptr2[3*(x1+Fishx[i])+2];
- }
- }
- }
- /*Show the taco*/
- if(taco==1){
- for (int y1=0; y1<PicTaco->height; y1++) {
- uchar* ptr1=(uchar*) (PicTaco->imageData +y1*PicTaco->widthStep);
- uchar* ptr2=(uchar*) (mergeImg->imageData +(y1+tacoy)*mergeImg->widthStep);
- for (int x1=0; x1<logoImg->width; x1++) {
- ptr2[3*(x1+tacox)]=alpha*ptr1[3*(x1)] + (1-alpha)*ptr2[3*(x1+tacox)];
- ptr2[3*(x1+tacox)+1]=alpha*ptr1[3*(x1)+1] + (1-alpha)*ptr2[3*(x1+tacox)+1];
- ptr2[3*(x1+tacox)+2]=alpha*ptr1[3*(x1)+2] + (1-alpha)*ptr2[3*(x1+tacox)+2];
- }
- }
- }
- /*Detect the Skin*/
- for (int y=0; y<grey->height; y++) {
- uchar* ptr1=(uchar*) (grey->imageData +y*grey->widthStep);
- for (int x=0; x<grey->width; x++) {
- if(ptr1[x]==255){
- MouseX=x;
- MouseY=grey->height-y;
- y=grey->height-1;
- x=grey->width-1;
- }
- }
- }
- /*Show the Mouse*/
- if( (MouseImg1->height + MouseY) > mergeImg->height)
- //MouseY = mergeImg->height - MouseImg1->height - 1;
- MouseY =MouseImg1->height - 1;
- for (int y1=0; y1<MouseImg1->height; y1++) {
- uchar* ptr1=(uchar*) (MouseImg1->imageData +y1*MouseImg1->widthStep);
- uchar* ptr7=(uchar*) (mergeImg->imageData +(y1+MouseY)*mergeImg->widthStep);
- for (int x1=0; x1<MouseImg1->width; x1++) {
- ptr7[3*(x1+MouseX)]=alphaf*ptr1[3*(x1)] + (1-alphaf)*ptr7[3*(x1+MouseX)];
- ptr7[3*(x1+MouseX)+1]=alphaf*ptr1[3*(x1)+1] + (1-alphaf)*ptr7[3*(x1+MouseX)+1];
- ptr7[3*(x1+MouseX)+2]=alphaf*ptr1[3*(x1)+2] + (1-alphaf)*ptr7[3*(x1+MouseX)+2];
- }
- }
- cvPutText(mergeImg,"Grade",TextPosition1,&Font1,Color);
- /*Show the user time*/
- cvPutText(mergeImg,"Time: ",TextPosition3,&Font1,Color);
- if(count%5==0){
- /*times[0]=(char)(count/5/10+48);
- times[1]=(char)(count/5%10+48);*/
- times[2]=(char)(count/5%10+48);
- times[1]=(char)((count/5/10)%10+48);
- times[0]=(char)(count/5/100+48) ;
- }
- cvPutText(mergeImg,times, TextPosition4, &Font1, Color);
- cvShowImage("DE", mergeImg);
- if(Grade==15){
- cvShowImage("DE",win);
- }
- /*Counting the grades and Fishes disapear*/
- for(int i=0;i<Fish;i++){
- double temp = sqrt((MouseX-Fishx[i])*(MouseX-Fishx[i])+(MouseY-Fishy[i])*(MouseY-Fishy[i]));
- if(temp<=12.0){
- Grade++;
- final[0]=(char)(Grade/10+48);
- final[1]=(char)(Grade%10+48);
- Fishx[i]=Fishx[Fish-1];
- Fishy[i]=Fishy[Fish-1];
- Fish--;
- }
- }
- cvPutText(mergeImg,final, TextPosition2, &Font1, Color);
- /*taco disapear and the page black*/
- if(taco==1){
- double tacotemp = sqrt((MouseX-tacox)*(MouseX-tacox)+(MouseY-tacoy)*(MouseY-tacoy));
- if(tacotemp <= 12.0){
- tacox=NULL;
- tacoy=NULL;
- taco=0;
- cvShowImage("DE",black);
- count+=15;
- cvWaitKey(3000);
- }
- }
- cvShowImage("DE", mergeImg);
- /*Pass Image*/
- if(Grade==15){
- cvShowImage("DE",win);
- }
- count+=1;
- cvWaitKey(200);
- }
- cvReleaseCapture(&capture);
- cvDestroyWindow("now");
- cvDestroyWindow("trans");
- cvDestroyWindow("Black");
- cvDestroyWindow("DE");
- }
複製代碼
它會顯示 [Warning] converting to `unsigned char' from `double'
請各位大大教我如何解決
... |
|