简体   繁体   English

更改帧类型而不丢失数据

[英]changing the frame type without loosing data

I'm using Opencv and I have two frame : cv::frame1 and cv::frame2, when I check their type I get : 我正在使用Opencv,我有两个框架:cv :: frame1和cv :: frame2,当我检查它们的类型时,我得到了:

 frame1.type()  is 16 
frame2.type() is 21

my Question is how can I change the type of frame2 to 16 without losing its data ?? 我的问题是如何在不丢失数据的情况下将frame2的类型更改为16? I tried frame2.convertTo() it didn't work . 我尝试了frame2.convertTo()无效。

any Idea ? 任何想法 ?

From what I understand you want to convert an image of type CV_32FC3 (3 channel float) to CV_8UC3 (3 channel unsigned char). 据我了解,您想将CV_32FC3类型的图像(3通道浮点数)转换为CV_8UC3(3通道无符号字符)。 This cannot be done without losing some information: In the first case you have 4 bytes per pixel and in the second 1 byte per pixel, so as you understand there is going to be some loss. 这不能不丢失一些信息来完成:在第一种情况下,每个像素有4个字节,在第二个情况下,每个像素有1个字节,因此,您将了解到会有一些损失。

This code is used to convert to a different type and works fine for me: 这段代码用于转换为其他类型,对我来说效果很好:

cv::Mat A = cv::Mat(480, 640, CV_32FC3, CV_RGB(1.0,1.0,1.0));
cv::Mat B;
A.convertTo(B, CV_8UC3);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM