![]() | + | ![]() | = | ![]() |
Example input to your method will be two file names denoting a target image (left), and source image (center). Output will be something like the result image (right) where part of the source image has been warped to fit within the frame in the target image.
This function should:
Useful matlab functions for this part are imread, ginput, floor, ceil, round. As always use help in matlab to get descriptions of each function (or look them up on google).
This function should:
Useful matlab functions for this part are cp2tform, imtransform, imresize, min, max. As always use help in matlab to get descriptions of each function (or look them up on google).
![]() |
+ | ![]() | = | ![]() |
| Input Video - frames.avi - Click to play. Uncompressed version available here | Selected frame that you want to embed, and selected rectangular region | Result video with embedded image - Click to play. Uncompressed version available here |
Load in your test video, frames2.avi.gz is an avi file containing a test movie and can be read in using aviread in matlab. Alternatively I have also provided a matfile containing the frames, frames.mat and can be read in using load in matlab.
First, choose the video frame that you want to embed (imagesc and pause are useful for viewing the frames of a video). Next, select the rectangular region of this video frame that you want to embed (source points). Make sure the part you select is perfectly rectangular otherwise your result video will have visual artifacts. For every video frame after your selected video frame, click on the four corners of the cardboard frame (target points). There have been colored dots placed at the corners to aid you in good localization. I would suggest saving these locations so that you only have to click on them once.
For every video frame after your selected video frame, compute the transform between the target points and source points. Transform the source region accordingly, and embed it in the target region. Here you will just need to apply your frameit.m function from Part 1!
Save the resulting video as result.avi. You can save an avi by creating an avifile object then repeatedly adding the video frames you have generated.
![]() |
+ | ![]() |
= | ![]() |
| Input Video - frames.avi - Click to play. Uncompressed version available here | Video that you want to embed - You will add this into the Input Video, offset in time. Click to play. Uncompressed version available here | Result video with embedded video - Click to play. Uncompressed version available here |
Instead of inserting a single static image into a set of frames, you can insert a different image into each frame, thereby embedding a video into a video. For every video frame after your selected video frame, insert a transformed frame from earlier in the video. For example if you are at video frame 120 and want your time offset to be -30 frames, then transform video frame 90 and embed it into the result video frame. You can either transform the whole image (as I have done in this example), or transform your hand selected regions, producing different effects.
Save the resulting video as extracredit.avi. You can save an avi by creating an avifile object then repeatedly adding the video frames you have generated.