今天接到一个任务,是从一个文件中将图片读取出来,文件是.out结尾的从摄像头上读取的图片,决定使用opencv来实现,刚好前端时间把浅墨的opencv入门书从头到尾又看了一遍,所有的程序也亲手重新过了一遍,但是还是感觉什么都不会,以后要多增加这方面的编程,纸上得来终觉浅,绝知此事要躬行。
下面直接看代码:
#include <stdio.h>
#include <vector>
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
int width = 1920;
int height = 1080;
int tmpLen = width * height * 3;
Size size(1920, 1080);
unsigned char* pBuffer = new unsigned char[tmpLen];
FILE* file = fopen("D:\\workspace\\Utils\\Data\\test2.out", "ab+");
if (nullptr == file)
{
cout << "Open file fail!" << endl;
return -1;
}
int i = 1;
while (i < 50)
{
fread(pBuffer, tmpLen, 1, file);
cv::Mat img = cv::Mat(size, CV_8UC1, pBuffer);
string img_name = "D:\\workspace\\Utils\\Data\\img\\" + to_string(i)