2013年5月26日 星期日

98360985_鄒金唐_上機考



考試題目:
        將畫面從中切成兩半,並在中間切割處畫上紅線,同時兩邊分別各有一頂不同皇冠,當頭移至右邊時,戴上右邊黃冠,左邊時,戴上左邊皇冠。

考試結果:
      紅線、皇冠沒有戴在頭上、也沒有去背,皇冠圖案沒有出現在左右(沒時間寫出來)

事後debug:
      皇冠戴在頭上
       for (int y=0; y<pink->height; y++) {  
            uchar* ptr1=(uchar*) (pink->imageData +y*pink->widthStep);
            for (int x=0; x<pink->width; x++) {     
                if(ptr1[x] ==255) 
                {
                               skinPixelNumber++;
                               skinPixelX+=x;
                               skinPixelY+=y;
                               }
                if(skinPixelNumber>0)
                {
                         mouseX=(int)(skinPixelX/skinPixelNumber)-50;
                         mouseY=(int)(skinPixelY/skinPixelNumber)-100;
                         }
        
        }
        }

位置稍微修改mouseXY即可


沒有去背:


 if(mouseX>160)
        {
        if( (crownleft->height + mouseX) < frame->height) {
            for (int y=0; y<crownleft->height; y++) {  
                uchar* ptr1=(uchar*) (crownleft->imageData +y*crownleft->widthStep);
                uchar* ptr2=(uchar*) (frame->imageData +(y+mouseY)*frame->widthStep);
                for (int x=0; x<(crownleft->width); x++) {
                     if(ptr1[3*(x)]!=255 && ptr1[3*(x)+1]!=255 && ptr1[3*(x)+2]!=255)
                    {     
                    ptr2[3*(x+mouseX)]=ptr1[3*(x)]; 
                    ptr2[3*(x+mouseX)+1]=ptr1[3*(x)+1]; 
                    ptr2[3*(x+mouseX)+2]=ptr1[3*(x)+2];   
                    } 
                    }
                    
                               }
                }    
                }
        if(mouseX<=160)
        {
        if( (crownright->height + mouseX) < frame->height) {
            for (int y=0; y<crownright->height; y++) {  
                uchar* ptr1=(uchar*) (crownright->imageData +y*crownright->widthStep);
                uchar* ptr2=(uchar*) (frame->imageData +(y+mouseY)*frame->widthStep);
                for (int x=0; x<(crownright->width); x++) { 
                    if(ptr1[3*(x)]!=255 && ptr1[3*(x)+1]!=255 && ptr1[3*(x)+2]!=255)
                    {
                    ptr2[3*(x+mouseX)]=ptr1[3*(x)]; 
                    ptr2[3*(x+mouseX)+1]=ptr1[3*(x)+1]; 
                    ptr2[3*(x+mouseX)+2]=ptr1[3*(x)+2];
                    }    
                    }
                    
                               }
                }    
                }

加了紅字那段就可以去背
一直想不到要怎麼去背
寫一個if即可



皇冠圖案出現在左右:

for (int y=0; y<crownright->height; y++) {  
                uchar* ptr1=(uchar*) (crownright->imageData +y*crownright->widthStep);
                uchar* ptr2=(uchar*) (frame->imageData +(y+y1)*frame->widthStep); 
                for (int x=0; x<crownright->width; x++) {     
                    ptr2[3*(x+x1)]=alpha*ptr1[3*(x)] + (1-alpha)*ptr2[3*(x+x1)]; 
                    ptr2[3*(x+x1)+1]=alpha*ptr1[3*(x)+1] + (1-alpha)*ptr2[3*(x+x1)+1]; 
                    ptr2[3*(x+x1)+2]=alpha*ptr1[3*(x)+2] + (1-alpha)*ptr2[3*(x+x1)+2];    
                    }
                }    
                
            
            for (int y=0; y<crownleft->height; y++) {  
                uchar* ptr1=(uchar*) (crownleft->imageData +y*crownleft->widthStep);
                uchar* ptr2=(uchar*) (frame->imageData +(y+y1)*frame->widthStep); 
                for (int x=0; x<crownleft->width; x++) {     
                    ptr2[3*(x+x2)]=alpha*ptr1[3*(x)] + (1-alpha)*ptr2[3*(x+x2)]; 
                    ptr2[3*(x+x2)+1]=alpha*ptr1[3*(x)+1] + (1-alpha)*ptr2[3*(x+x2)+1]; 
                    ptr2[3*(x+x2)+2]=alpha*ptr1[3*(x)+2] + (1-alpha)*ptr2[3*(x+x2)+2];    
                    }
                }    

考試實在de前面幾個bug沒有時間寫上去

考試之後補齊上去

考試心得:
      這次考試沒有說很難,只是需要一點時間我完成,最後還是順利寫出來了,感謝林志光同學的幫忙。

沒有留言:

張貼留言