opencv 保存的视频大小总为6KB

灵玲菱 2019-08-12 02:39:16
//#include "stdAfx.h"
#include <opencv2/core/core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <iostream>
#include <direct.h>//for mk_dir
#include <io.h>//for _acess()
using namespace cv;
using namespace std;

void Image2Video(string path_scr, string path_save);
//图片转视频
void Image2Video(string path_scr, string path_save)
{
char image_name[15];
string s_image_name;
VideoWriter writer;
int isColor = 0;
int frame_fps = 24;
int frame_width = 900;
int frame_height = 800;
string video_name = path_save + "out.avi";
writer = VideoWriter(video_name, CV_FOURCC('X', 'V', 'I', 'D'), frame_fps, Size(frame_width, frame_height), isColor);
cout << "frame_width is " << frame_width << endl;
cout << "frame_height is " << frame_height << endl;
cout << "frame_fps is " << frame_fps << endl;
namedWindow("image to video", 1);
int num = 167;//输入的图片总张数
int i = 1;
Mat img;
while (i <= num)
{
sprintf(image_name, "%d%s", ++i, ".jpg");
s_image_name = path_scr + image_name;
img = imread(s_image_name);//读入图片
if (!img.data)//判断图片调入是否成功
{
cout << "Could not load image file...\n" << endl;
}

//写入
writer<<img;
imshow("image to video", img);
if (waitKey(30) == 27 || i > 166)
{
cout << "touch ESC" << endl;
break;
}
}

}


int main(int argc, char** argv)
{
// string videoFromfile = "E:\\face.mp4"; //读取视频
string Imagespath = "F:\\Visual Studio 2013\\12\\"; // 保存图片的文件夹路径一定要有,因为OpenCV不会自动创建文件夹
string videoTosave = "F:\\Visual Studio 2013\\"; //保存视频路径
//video2image(videoFromfile,Imagespath);
Image2Video(Imagespath, videoTosave);
return 0;
}
...全文
413 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
灵玲菱 2019-08-18
  • 打赏
  • 举报
回复
引用 4 楼 赵4老师 的回复:
文件路径中不要带汉字和空格。
确保将opencv_ffmpeg*.dll拷贝到
exe文件所在目录下

项目、属性、调试、工作目录下。
必要的话,*vfw*.dll也得拷贝。
谢谢您,解决了
赵4老师 2019-08-13
  • 打赏
  • 举报
回复
文件路径中不要带汉字和空格。 确保将opencv_ffmpeg*.dll拷贝到 exe文件所在目录下 和 项目、属性、调试、工作目录下。 必要的话,*vfw*.dll也得拷贝。
灵玲菱 2019-08-13
  • 打赏
  • 举报
回复
引用 1 楼 赵4老师 的回复:
将opencv*.dll拷贝到你exe所在文件夹下。
已经尝试过仍不行,图片可以写入并可以显示视频,但无法保存,还请指教,谢谢
轻箬笠 2019-08-12
  • 打赏
  • 举报
回复
6k的视频明显错了,单步跟踪看看
赵4老师 2019-08-12
  • 打赏
  • 举报
回复
将opencv*.dll拷贝到你exe所在文件夹下。

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧