play video within video
Here is my code which overlays an image ( replace1.jpg) on live camera feed. how can I play a video ( say .avi ) file in the specified area ? or what if I would like to play a sound ?
Mat repImage = imread("replace1.jpg");
vector<Point2f> imagePoints = { Point2f(0, 0), Point2f(repImage.cols, 0), Point2f(repImage.cols, repImage.rows), Point2f(0, repImage.rows), };
Mat transmix = getPerspectiveTransform(imagePoints, newLEDPoints);
warpPerspective(repImage, cameraFeed, transmix, cameraFeed.size(), cv::INTER_LINEAR, cv::BORDER_TRANSPARENT);
If I would like to play replace1.avi instead of displaying replace1.jpg how can it be possible?
I don't really understand what you're trying to achieve with this code. You're applying a perspective transformation but you don't need that to overlay an image... Anyway, what do you mean by playing video, showing it? Then you just need to use the matrix that is storing the corresponding frames
@Lorena GdL this is part of an AR solution which needs to do perspective transformation. I identify the coordinates of markers in Live camera feed (newLEDPoints in code) and need to display additional information ( image replace1.jpg) at the position defined by markers. This is working fine. Now I would like to play a video within live camera frame at position defined by vertices of rectangle stored in newLEDPoints. I have added image in the question for clarity As you can see four points have been identified in Live Camera Feed and an image has been displayed after perspective transformation. If I would like to play a .avi file instead of displaying simple image on top of live camera feed, how can I do so?
As I said, you just need to replace the matrix containing the static image by the matrix containing the corresponding video frame, i.e. instead of using the
Mat repImage
use theMat frame
which is storing frames through the VideoCapture class:VideoCapture cap("myvideo.avi"); Mat frame; for(;;){ cap >> frame;}
You'll just need to be careful with synchronization and so on