我有一个项目需要在视频中插入内容或从视频中删除项目(例如汽车)。我的概念如下:
有人能告诉我示例代码或一些参考吗?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <cv.h>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/background_segm.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
CvCapture* cap = NULL;
Mat frame;
Mat edges;
BackgroundSubtractorMOG2 bg;
int main (int argc, char *argv[]) {
cap = cvCreateFileCapture("inputfilehere");
if(!cap)
return -1;
bg.set("nmixtures", 6);
bg.set("detectShadows",false);
//namedWindow("edges",CV_WINDOW_FREERATIO);
//namedWindow("result",CV_WINDOW_AUTOSIZE);
while(1){
frame = cvQueryFrame(cap);
Mat img;
img = frame;
cvtColor(frame, edges, CV_BGR2GRAY);
Mat roi = img(Rect(130,300,70,40)); // the car location from my video or whatever object
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("Input Video", frame);
imshow("ROI",roi);
printf("Value: %d\n", static_cast<int>(frame.at<uchar>(0,0)));
//system("PAUSE");
if(waitKey(30) >= 0) break;
}
return 0;
}
答案 0 :(得分:-1)
我做过这个话题。
我认为屏幕稳定。 我想你可以按照以下步骤操作: