序列帧视频raw格式数据的存储和读取

常用的raw格式有12位和14位之分。本次实验是将16位的帧序列图片存储到raw二进制文件中,在从读取raw文件成16位的序列图片。

直接上代码!!

raw格式文件的保存:

#include<opencv2\opencv.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include<math.h>
using namespace std;
using namespace cv;
int num = 0;
int main()
{
    std::vector<int>compression_params;
	compression_params.push_back(IMWRITE_PNG_COMPRESSION);   //CV_IMWRITE_PNG_COMPRESSION
	compression_params.push_back(9);///无压缩png
    
    ofstream out_RAW;
	out_RAW.open(rawFile_name, ios::out | ios::app | ios::binary);

	if (!out_RAW.is_open())
	{
		cout << "read file error!" << endl;
		return 0;
	}
    int imageh = 200;  //图片大小
	int imagew = 200;
    string file_name="...\\image"+to_string(num)+".png";
    string Raw_Name="...\\imageRaw.raw";
    for(;num<1000;num++)
    {
         string file_name="...\\image"+to_string(num)+".png";
         Mat Image=imread(file_name,2);
        out_RAW.write((char*)Image.data, 2 * imageh*imagew);
		out_RAW.flush();
		Sleep(1);
    }
   return 0;
}

raw文件的读取到png图片

#include<opencv2\opencv.hpp>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
using namespace std;
using namespace cv;
int num = 0;
int main()
{
    std::vector<int>compression_params;
	compression_params.push_back(IMWRITE_PNG_COMPRESSION);   //CV_IMWRITE_PNG_COMPRESSION
	compression_params.push_back(9);///无压缩png

    int imageh = 200;
	int imagew = 200;
    string filename = "...\\image_Raw.raw";
    ifstream inFile(filename , ios::in | ios::binary);
	if (!inFile)
	{
		cout << "read file error!" << endl;
		return 1;
	}
    for(;num<1000;num++)
    {
        string image_name="...\\image_"+to_string(num)+".png";
        Mat image(imagew, imageh, CV_16UC1);
		inFile.read((char*)image.data, 2 * imageh*imagew);
        imwrite(image_name,image,compression_params);
    }
    return 0;
}

 

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LabVIEW是一款强大的图形化编程软件,用于数据采集和处理。在LabVIEW中,可以使用不同的方式读取raw格式数据。 第一种方法是使用File I/O函数,通过打开文件读取数据和关闭文件的操作来读取raw格式数据。可以使用"Open/Create/Replace File"函数打开要读取raw文件,然后使用"Read from Binary File"函数来读取数据,最后使用"Close File"函数关闭文件。 第二种方法是使用NI-DAQmx驱动进行数据采集。可以使用"DAQmx Create Task"函数创建任务,设置任务的采样率、采样点数等参数,然后调用"DAQmx Read"函数读取raw数据。这个方法适用于需要实时采集数据的情况。 第三种方法是使用第三方工具包。LabVIEW有许多第三方工具包可以用于读取各种格式数据,包括raw格式数据。你可以在LabVIEW的官方网站或者其他相关资源网站上搜索并下载适用于读取raw数据的工具包,然后在LabVIEW中安装和使用。 无论使用哪种方法,都需要注意raw数据格式和字节顺序。因为raw数据是未经处理的二进制数据,可以是任意格式和字节顺序。在读取raw数据之前,需要确定raw数据格式和字节顺序,然后按照相应的规则进行解析和处理。 总之,LabVIEW提供了多种方式来读取raw格式数据,你可以根据具体的需求选择适合的方法。无论使用哪种方法,都需要注意raw数据格式和字节顺序,在数据采集和处理过程中保证数据的准确性和可靠性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值