【发布时间】:2014-09-29 15:47:13
【问题描述】:
我调查并删除了我之前的问题 (Is there a way to avoid conversion from YUV to BGR?)。我想在生成的更大图像上叠加少量图像(格式为 YUV)(将其视为画布)并通过网络库 (OPAL) 将其发送,而不将其转换为 BGR。
代码如下:
Mat tYUV;
Mat tClonedYUV;
Mat tBGR;
Mat tMergedFrame;
int tMergedFrameWidth = 1000;
int tMergedFrameHeight = 800;
int tMergedFrameHalfWidth = tMergedFrameWidth / 2;
tYUV = Mat(tHeader->height * 1.5f, tHeader->width, CV_8UC1, OPAL_VIDEO_FRAME_DATA_PTR(tHeader));
tClonedYUV = tYUV.clone();
tMergedFrame = Mat(Size(tMergedFrameWidth, tMergedFrameHeight), tYUV.type(), cv::Scalar(0, 0, 0));
tYUV.copyTo(tMergedFrame(cv::Rect(0, 0, tYUV.cols > tMergedFrameWidth ? tMergedFrameWidth : tYUV.cols, tYUV.rows > tMergedFrameHeight ? tMergedFrameHeight : tYUV.rows)));
tClonedYUV.copyTo(tMergedFrame(cv::Rect(tMergedFrameHalfWidth, 0, tYUV.cols > tMergedFrameHalfWidth ? tMergedFrameHalfWidth : tYUV.cols, tYUV.rows > tMergedFrameHeight ? tMergedFrameHeight : tYUV.rows)));
namedWindow("merged frame", 1);
imshow("merged frame", tMergedFrame);
waitKey(10);
上述代码的结果如下所示:
我猜图像没有正确解释,所以图片保持黑/白(Y 分量),在它们下方,我们可以看到 U 和 V 分量。有图片,很好地描述了问题(http://en.wikipedia.org/wiki/YUV):
和:http://upload.wikimedia.org/wikipedia/en/0/0d/Yuv420.svg
有没有办法正确读取这些值?我想我不应该将整个图像(它们的 Y、U、V 分量)直接复制到计算出的位置。 U 和 V 分量应该在它们下方并且按正确的顺序排列,对吗?
【问题讨论】:
-
tYUV 的类型应该是 CV_8UC3,(如果你想要所有 3 个 yuv 通道)。此外,如果您只有 w*h 像素,则无法像您一样将图像放大。 (
tHeader->height * 1.5f必须离开) -
我在 OpenCV 文档中找不到任何线索,它是否能够在 YUV 模式下执行“copyTo() 子图像”(由于数据的组织,它一定是一团糟),事实上,图像绝对不再以矩阵的形式组织了
-
@berak 我不太明白为什么我应该有三个频道。 AFAIK,如果我有图像
x像素宽和y像素高,在 YUV 格式中,我将获得 Y 分量的x * y数字,U 的x * y / 4数字和 V 分量的x * y / 4数字。所以总的来说我有1.5 * x * y号码。这就是为什么我把那个tHeader->height * 1.5f.
标签: c++ opencv image-processing merge yuv