日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

opencv实现两个视频拼接显示

發(fā)布時間:2024/3/24 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 opencv实现两个视频拼接显示 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Mat實現將兩列視頻幀文件顯示在同一個視頻中
注釋是之前使用IplImage指針實現的,但是由于運行了幾次后出現了內存訪問沖突的問題,所以就改用了Mat類,感興趣的可以試著用IplImage實現下,兩種版本都是可以運行的。

//將兩個視頻并列在一個視頻中播放 #include <opencv2\opencv.hpp> #include <opencv2\core\core.hpp> #include <opencv2\highgui\highgui.hpp> using namespace std; using namespace cv;int main() {Mat depth = imread("F:/3DImageProcess/MSProjection/MSProjection/MSProjection/results/cam7/warp-depth-f000.png");Mat image = imread("F:/3DImageProcess/MSProjection/MSProjection/MSProjection/results/cam7/warp-img-f000.png");int liv_width = depth.cols + image.cols;int liv_height = image.rows;int liv_nChannels = image.channels();VideoWriter videoWriter("F:/3DImageProcess/MSProjection/MSProjection/MSProjection/results/cam7/warp-result.avi",CV_FOURCC('M','J','P','G'),20,Size(liv_width,liv_height));//IplImage *lpv_firstFrame1 = cvLoadImage("F:/3DImageProcess/MSProjection/MSProjection/MSProjection/results/cam7/final-depth-f000.png");//IplImage *lpv_firstFrame2 = cvLoadImage("F:/3DImageProcess/MSProjection/MSProjection/MSProjection/results/cam7/final-img-f000.png");//int liv_width = lpv_firstFrame1->width+lpv_firstFrame2->width;//int liv_height = lpv_firstFrame2->height;//int liv_nChannels = lpv_firstFrame2->nChannels;// 初始化CvVideoWriter//CvVideoWriter* videoWriter = cvCreateVideoWriter("final-result.avi",CV_FOURCC('X', 'V', 'I', 'D'), 20, cvSize(liv_width, liv_height),1);/*IplImage *lpv_imageFrame1;IplImage *lpv_imageFrame2;*//*Mat image1;Mat image2;*///用于表示處于視頻的多少幀int i = 0; char imageDir1[256], imageDir2[256]; //略大于讀入文件目錄的總字符數,防止因為'\0'而出現棧溢出的情況/*sprintf(imageDir1, "F:/3DImageProcess/MSProjection/MSProjection/MSProjection/results/cam7/final-depth-f%03d.png", i);sprintf(imageDir2, "F:/3DImageProcess/MSProjection/MSProjection/MSProjection/results/cam7/final-image-f%03d.png", i);*//*image1 = imread(imageDir1);image2 = imread(imageDir2);*///while ((lpv_imageFrame1 = cvLoadImage(imageDir1))&&(lpv_imageFrame2=cvLoadImage(imageDir2)))//while (image1.empty()&&image2.empty())while (!(depth.empty() && image.empty())){Rect rectd = Rect(0, 0, depth.cols, depth.rows);Rect recti = Rect(depth.cols, 0, image.cols, image.rows);Mat dstImage;dstImage.create(Size(liv_width,liv_height),image.type());/*image1.copyTo(Mat(dstImage, rectd));image2.copyTo(Mat(dstImage, recti));*/depth.copyTo(Mat(dstImage, rectd));image.copyTo(Mat(dstImage, recti));videoWriter << dstImage;i++;sprintf(imageDir1, "F:/3DImageProcess/MSProjection/MSProjection/MSProjection/results/cam7/warp-depth-f%03d.png", i);sprintf(imageDir2, "F:/3DImageProcess/MSProjection/MSProjection/MSProjection/results/cam7/warp-img-f%03d.png", i);depth = imread(imageDir1);image = imread(imageDir2);//兩個ROI區(qū)域/*CvRect rect1 = cvRect(0, 0, lpv_imageFrame1->width, lpv_imageFrame1->height);CvRect rect2 = cvRect(lpv_imageFrame1->width, 0, lpv_imageFrame2->width, lpv_imageFrame2->height);*///img1 img2 原圖 dst1、dst2放縮后的圖 dst_big 大圖 *dst1, *dst2, //IplImage *dst_big = cvCreateImage(cvSize(lpv_imageFrame1->width + lpv_imageFrame2->width, lpv_imageFrame2->height), lpv_imageFrame2->depth, 3);設置ROI//cvSetImageROI(dst_big, rect1);//cvCopy(lpv_imageFrame1, dst_big);//cvSetImageROI(dst_big, rect2);//cvCopy(lpv_imageFrame2, dst_big);//cvWriteFrame(videoWriter, dst_big);//為什么沒法即時顯示圖像?/*IplImage *dt = cvCreateImage(cvSize(1000, 375), lpv_imageFrame2->depth, 3);cvResize(dst_big, dt);cvShowImage("imageFrame", dt);*/釋放ROI//cvResetImageROI(dst_big);//釋放圖像空間 //cvReleaseImage(&dst_big);cvReleaseImage(&dt);}必須釋放,否則會出現寫好的視頻丟失總幀數、不能快進的問題//cvReleaseVideoWriter(&videoWriter); // //釋放圖像空間//cvReleaseImage(&lpv_firstFrame1);//cvReleaseImage(&lpv_firstFrame2);//cvReleaseImage(&lpv_imageFrame1);//cvReleaseImage(&lpv_imageFrame1);return 0; }

最終的效果圖如下:

總結

以上是生活随笔為你收集整理的opencv实现两个视频拼接显示的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。