Hi guy's
I am working on a sprite game in c++ and OpenCV. I have created to images, the backgroundimage (the background image in the game and the spriteman (my character in the game).
How do I remove the colour blue colour around my character?
I am working on a sprite game in c++ and OpenCV. I have created to images, the backgroundimage (the background image in the game and the spriteman (my character in the game).
How do I remove the colour blue colour around my character?
Code:
int main() {
// Loading Images - Loading the Background Image
IplImage* backgroundimage = cvLoadImage("mission11.png");
backgroundimage->width;
backgroundimage->height;
// Creating an empty images - Setting the widt and height values as backgroundimage
IplImage* temp = cvCreateImage(cvSize(backgroundimage->width,backgroundimage->height),IPL_DEPTH_8U,3) ;
// Loading Images - Loading the Sprite Image
IplImage* spriteman = cvLoadImage("spriteman.jpg"); //change the file name with your own image
spriteman->width;
spriteman->height;
// The start place of the sprite
int placeY = 80;
int placeX = 80;
// Creating a variable for the keys ind the game
char presskey;
// The start place of the sprite
bool run = true;
while(run){
char presskey = cvWaitKey(5);
switch(presskey) {
case 'w':
case 38:
placeY -=10;
break;
case 'a':
case 39:
placeX -=10;
break;
case'd':
case 40:
placeX +=10;
break;
case's':
case 41:
placeY +=10;
break;
case 32:
placeY -=20;
break;
case'q':
case 27:
run=false;
break;
}
for(int i=0;i<backgroundimage->height*backgroundimage->width*backgroundimage->nChannels;i++){
temp->imageData[i]=backgroundimage->imageData[i];
}
for(int y = 0; y < spriteman->height; y++){
for(int x = 0; x < spriteman->width; x++){
for(int z = 0; z < spriteman->nChannels; z++){
if(((uchar *)(spriteman->imageData + y*spriteman->widthStep))[x*spriteman->nChannels + z] < 260){
temp->imageData[(y + placeY) * backgroundimage->widthStep + (x+placeX) * backgroundimage->nChannels + z] = spriteman->imageData[y * spriteman->widthStep + x * spriteman->nChannels + z];
}
}
}
}
// Display the image temp
cvShowImage("Metal Slug: Kill Rambo", temp);
}
//create a new window with
cvNamedWindow("Metal Slug: Kill Rambo", CV_WINDOW_FULLSCREEN);
//Destroying the Window and the Images within
cvDestroyWindow( "Metal Slug: Kill Rambo" );
cvReleaseImage( &backgroundimage );
cvReleaseImage( &temp );
cvReleaseImage( &spriteman );
return 0;
}
Comment