用opencv將連續編號的圖片儲存為avi視頻 【有問題,如果你看到,請指教~】

來源:互聯網
上載者:User

代碼如下:

#include"stdafx.h"#include <stdio.h>#include <cv.h>#include <highgui.h>int main(){int i = 0;  IplImage* img = 0;  char image_name[25];  CvVideoWriter *writer = 0;  int isColor = 1;  int fps     = 30; // or 25  writer=cvCreateVideoWriter("..\\out.avi",CV_FOURCC('X','V','I','D'),fps,cvSize(640,480),isColor);  cvNamedWindow("vivi");  while(1)  {  sprintf(image_name, "%s%d%s", "..\\tutu\\image", ++i, ".jpg");img = cvLoadImage(image_name, -1);if(img == NULL)break;cvShowImage("vivi", img);  char key = cvWaitKey(20);  cvWriteFrame(writer, img);  img = NULL;}  cvReleaseVideoWriter(&writer);  cvDestroyWindow("vivi");  return 0;}

很簡單的代碼。

這個程式,第一次用來跑的時候,很順利 成功 產生了 avi 視頻。

第二次跑的時候,就發生地址衝突了。沒能成功產生視頻檔案。

很鬱悶== 應該是 cvWriteFrame 這個地方有問題。。。

就這麼簡短,還真沒看出哪裡有問題來。

 如果你恰好看到了,請告訴我撒~~~

=================

後記:

後來搜了好多,看到好多網友也說  opencv2.1 cvVideoWriter 有問題。

換成 opencv2.2 之後就OK了。。。

額 。。 還沒有安裝 2.2, 但是 貌似看到網上寫的, 2.2 的 debug版本 是 OK的, release 版本 也有問題。

就是說 220d.dll 是OK的, 220.dll 是有點問題的。

具體,用到的時候再解決吧。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.