当前位置: 代码迷 >> 综合 >> 常用代码段 1将图片压为 .avi 视频 2 .jpg和.png 互转 3 视频解帧
  详细解决方案

常用代码段 1将图片压为 .avi 视频 2 .jpg和.png 互转 3 视频解帧

热度:20   发布时间:2024-01-18 17:46:35.0
 void image2video()
{// ???ì????VideoWriterVideoWriter video("test.avi", CV_FOURCC('M', 'J', 'P', 'G'), 501, Size(1920, 1080));String pattern = "G:\\????????\\tozfb\\*.jpg";vector<String> fn;glob(pattern, fn, false);size_t count = fn.size();for (size_t i = 0; i < count; i++){Mat image = imread(fn[i]);video << image;}cout << "???í?ê±???" << endl;
}void jpg2png()
{string imgFloder = "G:\\DataSet\\????????\\basketball_court";string path2png = "G:\\DataSet\\????????\\basketball_png\\";std::vector<cv::String> img_names;cv::glob(imgFloder, img_names);	//read images from floderint num_images = img_names.size();cout << "number of stitch image : " << img_names.size() << endl;int i = 0;for (cv::String name : img_names){cv::Mat image = cv::imread(name);char ss[10];sprintf(ss, "%04d", i++);string path = path2png + string(ss) + ".png";std::cout << "ori name??" << name << std::endl;std::cout << " mod name:" << path << std::endl;cv::imwrite(path, image);}std::cout << "???í?ê±?" << std::endl;
}void toFrame()
{string videoPath = "/home/frank804/Documents/python/tool/DJI_0001.MP4";string imagesPath = "/home/frank804/Documents/python/tool/png/";VideoCapture cap;cap.open(videoPath);if (cap.isOpened()) {Mat frame;int n = 0;while (cap.read(frame)){imshow("frame", frame);waitKey(10);char imgPath[256];sprintf(imgPath, "%s%04d.png", imagesPath.c_str(), n++);imwrite(imgPath, frame);}cap.release();}else {cout << "Can't open the video file!" << endl;return ;}std::cout<<"successfully getting frame sequences !!!!"<<std::endl;      return ; 
}

 

  相关解决方案