Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Main Aim:Back ground image should be fixed and the dinosaur must look like chasing the girl and the images are to be taken are fixed

Main Aim:Back ground image should be fixed and the dinosaur must look like chasing the girl and the images are to be taken are fixed and the dinosaur and girl images must be masked.I have also given the base code.Please make necessary changes to get the ouput.

Instructions

For this project, you are expected to build a 2D based animation, which is often used in video gaming. Below is a captured frame showing what you need to achieve. The basic goal is to let you load different images, and synthesize a new image by putting different images together, and display the final image sequentially to screen.

Project Description:

This animation is about a dinosaur chasing a girl in the forest. To achieve this effect, there are three basic objects involved: a girl, a dinosaur, and a moving background. The relative positions of the dinosaur and the girl can be flexible, as long as the dinosaur is to the left of the girl, which makes sense. You can place the girl in the middle of the image. In practice, you do not need to change the positions of the girl and the dinosaur once the program starts. What you need to do is to load different images (about different poses of the girl and dinosaur) and copy them into the final image sequentially, meanwhile copy different parts of the background image using slide window mechanism to generate the animation effects. All the images involved for this animation have been provided in the attachment.

Project Goal:

  • Get familiar with OpenCV by practicing different functions, including imread( ), imshow( ), create( ), waitKey( ), copyTo( ), Range( ).

  • Understand the process of 2D based animation.

  • Learn the role of using mask in image processing.

  • Practice implementing user interactivity by programming on mouse/keyboard event.

Suggested Steps:

(1) To get started, you first create a function, say loadImages() to load all the images into the memory by using imread(). (hint: if you feel it is tedious to type each individual image name, you can use the sprintf() function from c++ and load those images by a loop)

(2) You can use the create( ) function (that is the member function of cv::Mat) to create a screen image, which is used to hold and display the background, the dinosaur, and the girl together. You can make this screen image the same height as the background image (bg_scene.jpg), but a little narrower than the width of the bg_scene.jpg. Initially, this screen image is in black color.

(3) Then you can copy one of the girl image into the screen image. There is no exact location requirement for the girl in the screen. You can put it in the middle of the image as the screenshot shows.

(4) If you succeed, then you can try to copy one dinosaur image to the screen in the same way.

(5) To animate the girl and dinosaur to run, you need to put step (3) and (4) into a loop. For each iteration, different girl or dinosaur image is copied to the screen based on the loop index.

(6) Finally, you need to manage to do the rolling background. The basic idea is to copy different part of the bg_scene.jpg into the screen image to generate a moving effect. This part is talked in the class.

Rubrics:

(1) Successfully load all the images into memory. (20%)

(2) Successfully create the screen image. (10%)

(3) Successfully generate animation for the girl and the dinosaur (40% with the three sub-parts below)

  • use copyTo( ) and Range( ) to copy a girl (or dinosaur) image to the screen (15%)

  • correctly use mask image (10%)

  • use a loop to copy different posed figure into the screen (15%)

(4) Successfully generate rolling background (30%)

Bonus Points:

(5) Your program allows the user to use mouse or keyboard to change the location of the girl and dinosaur. For example, the key d to let the two objects move towards right; a - moves towards left; w-moves up; s-moves down (20%)

Base Code:

 #include  #include  #include  #include  #include  using namespace cv; //It tells the rest of the code, all the types or functions are from the opencv library Mat bg_img; Mat dinosaur_img; Mat dinosaur_mask; int tx,ty; int bx, by; void onMouse(int event, int x, int y, int flags, void* userdata) { if ( event == EVENT_LBUTTONDOWN) { printf("(%d, %d) ", x, y); tx = x; ty = y; tx = x; ty = y; bx = tx +dinosaur_img.cols; by = ty + dinosaur_img.rows; } } void copyImg() { bg_img = imread("bg_scene.jpg"); for(int y = ty; y < by; y++) { for(int x = tx; x < bx; x++) { bg_img.ptr(y)[3 * x] = dinosaur_img.ptr(y - ty)[3 * (x - tx)]; bg_img.ptr(y)[3 * x + 1] = dinosaur_img.ptr(y - ty)[3 * (x - tx) + 1]; bg_img.ptr(y)[3 * x + 2] = dinosaur_img.ptr(y - ty)[3 * (x - tx) + 2]; } } } int main() { namedWindow("bg_scene", 1); //this is necessary only if you want this window to have a handler of mouse event setMouseCallback("bg_scene", onMouse); bg_img = imread("bg_scene.jpg"); //if it has second parameter 0, it is treated as a grey image dinosaur_img = imread("dinosaur00.jpg"); dinosaur_mask = imread("dinosaur_mask_00.bmp", 0); //mask image is stored as the original image "bitmap"; 0 - load it as a single channel image // x.copyTo(bg_img); //To show an image, you need to put imshow in a loop //while(1) - inifite while loop for(;;) //infitie for loop { copyImg(); imshow("bg_scene", bg_img); imshow("dinosaur", dinosaur_img); imshow("dinosaur mask", dinosaur_mask); char c = waitKey(100); //Tell opencv to detect the keyboard event in every second if(c == 27 || c == 'f' || c == 'F') //27 is the ESc ASCII code break; } }

Please provide me an email to send the images required for this program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Define indirect financial compensation (employee benefits).

Answered: 1 week ago

Question

How to find if any no. is divisble by 4 or not ?

Answered: 1 week ago

Question

Explain the Pascals Law ?

Answered: 1 week ago

Question

What are the objectives of performance appraisal ?

Answered: 1 week ago

Question

Use of assessments to determine trainees learning styles.

Answered: 1 week ago

Question

7. Discuss the advantages of embedded learning.

Answered: 1 week ago