添加图像叠加的OpenCV为Android [英] Adding Image Overlay OpenCV for Android

查看:489
本文介绍了添加图像叠加的OpenCV为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找叠加在OpenCV中(2.4.3)的图像为Android的一种方式。基本上,我做了一些图像过滤,我希望用户能够看到清晰过滤视频流,但在上风角落看到什么样的过滤器做了preVIEW:

I am looking for a way to overlay an image in openCV(2.4.3) for Android. Basically, I am doing some image filtering, and I want the user to be able to see the cleanly filtered video stream, but in the upper hand corner see a preview of what the filter is doing:

我曾尝试过滤的图像上设定的投资回报率,并在JNI code像这样使用AddWeighted

I have tried setting an ROI on the filtered image, and the using AddWeighted in JNI code like this

在活动:

liveFrame.copyTo(mRgba); //going to be used as the unfiltered stream

//image filtering happends here...

Rect roi = new Rect(0, 0, liveFrame.cols()/4, liveFrame.rows()/4);
mProcMat = new Mat(liveFrame, roi);
AddMats(mRgba.getNativeObjAddr(),mProcMat.getNativeObjAddr()); //will add the two, assign the result to mRgba

AddMats(本机方法):

AddMats (Native Method):

Mat* image1=(Mat*)mat1;
Mat* image2 = (Mat*)mat2;
float alpha = 0.5;
float beta = 0.5;
addWeighted( (InputArray)*image1, alpha, (InputArray)*image2, beta, 0.0, (OutputArray)*image1);

但是,这不会工作,因为图像的大小必须是一样的,所以我不能似乎想办法得到这个工作。我可以在iOS的轻松做到这一点,因为你可以只是简单地套用帧的实时流的顶部有一个新的看法。对于Android,据我所知,你只能有每个摄像机输入流1面视图。所以,这就是为什么我去了在OpenCV中这样的路径,但我认为在这一点上的任何解决方案

But this wont work because the size of the images has to be the same, so I cant seem to think of a way to get this to work. I can do this easily in iOS, because you can simply just apply the frame to a new view on top of the live stream. For Android, as far as I know, you can only have 1 surface view per camera input stream. So thats why I went down the path of doing this in opencv, but I would consider ANY solution at this point

推荐答案

如果我理解正确的话,你想现场图像显示保持不变,并在上风角落应用一些过滤器,实时图像的结果,是这正确吗?
你想过滤的preVIEW重新present整个图像或只是其中的一部分?

If I understood correctly, you want a live image to be displayed unaltered, and in the upper hand corner the result of applying some filter to the live image, is this correct? You want the filtered preview to represent the whole image or just part of it?

下面是一个算法,我想你想要做什么:

Here is an algorithm that I think does what you want:

第1步:调整liveFrame(不改变它,所以你可以创建一个副本,或使用其内部创建一个副本的大小调整的方法),所以它是一种新的图像(称为mProcMat)比小原版的。 你可能要检查这个问题。

Step 1: resize liveFrame (without altering it, so you either create a copy or use a resize method which creates a copy internally) so it is a new image (called mProcMat) smaller than the original. You might want to check this question.

第二步:应用图像过滤来mProcMat

Step 2: apply image filtering to mProcMat.

第3步:放置mProcMat上liveFrame,创建一个liveFrame它的投资回报率定位在其右上角的,并具有mProcMat相同尺寸即可。使用submat的投资回报率,有您在您的其他问题看出,它更灵活,因为你有3个不同的方式设置它。

Step 3: to place the mProcMat on the liveFrame, create a ROI on liveFrame which is positioned on its upper right and has the same size of mProcMat. Use submat for the ROI, has you have seen in your other question, it is more flexible because you have 3 different ways to set it up.

第四步: AddMats(liveFrameROI.getNativeObjAddr(),mProcMat.getNativeObjAddr());

这听起来好?

编辑:
我甚至不认为你需要做的第4步addWeighted,拿到preVIEW你可以只画上mProcMat从第3步的投资回报率我没有完全理解你的想法用addWeighted。

I don't even think you need to do addWeighted of the 4th step, to get the preview you could just paint mProcMat on the roi from step 3. I didn't understand completely your idea to use addWeighted.

您可能还需要检查此线程,它是某种类似。

You might also want to check this thread, it is somehow similar.

这篇关于添加图像叠加的OpenCV为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆