OpenCV for Android:如何将 Mat 对象(图像)复制到另一个 Mat?
两个 Mat 对象都包含(不同的)图像。我想通过 mRgba
复制 mSnapshot
。 我(分别)尝试了这些,但它们似乎都没有改变 mRgba
:
mSnapshot.assignTo(mRgba);
mSnapshot.copyTo(mRgba);
mRgba = mSnapshot;
这会引发异常:
mRgba.setTo(mSnapshot);
这确实有效,并将 mRgba
设置为全黑图像:
mRgba.setTo(new Scalar(0,0,0,255));
我缺少什么?
[编辑] 您可以在此处找到源文件和例外情况。
Both Mat objects contain (different) images. I want to copy mSnapshot
over mRgba
.
I tried these (separately), but none of them seem to change mRgba
:
mSnapshot.assignTo(mRgba);
mSnapshot.copyTo(mRgba);
mRgba = mSnapshot;
This throws an exception:
mRgba.setTo(mSnapshot);
And this does work, and sets mRgba
to be a completely black image:
mRgba.setTo(new Scalar(0,0,0,255));
What am I missing?
[Edit]
The source files and exception can be found here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要复制图像,您应该使用
clone()
成员函数,如下所示:另请注意,OpenCV 按 BGR 顺序存储信息;因此,您的行:
为清楚起见进行了编辑:此命令将每个像素设置为 (0, 0, 0, 255),因此通道 1-3 设置为 0,通道 4 (alpha) 为设置为 255。如果您尝试这样做会怎样:
另外,请注意,您只能在分配矩阵后使用
setTo
。希望有帮助!
To copy an image, you should use the
clone()
member function like this:Another note, OpenCV stores information in BGR order; therefore, your line:
Edited for clarity : This command is setting each pixel to (0, 0, 0, 255), so channels 1-3 are set to 0, and channel 4 (alpha) is set to 255. What if you tried this:
Also, note that you can only use
setTo
once the matrix is allocated.Hope that helps!