简体   繁体   English

如何从相机预览中检测现有图像?

[英]How to detect an existing image from camera preview?

我必须从摄像头预览中检测到android项目中的现有图像,而不需要拍摄图像,我到处都是,但我发现我必须使用opencv,但找不到很好的示例(解决方案必须看起来像条形码检测)如果有任何想法,请告诉我谢谢。

What do you mean by "Existing Image"? 您所说的“现有图像”是什么意思? Do you have the physical address of the image? 您有图片的物理地址吗? If so, you can load image with opencv android wrapper. 如果是这样,您可以使用opencv android包装器加载图片。 For instance, if you know the physical address of the image, then you can load it and send it to ImageView using the following codes: 例如,如果您知道图像的物理地址,则可以使用以下代码加载它并将其发送到ImageView:

BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();

Mat m = Imgcodecs.imread(picturePath);

Bitmap bm = Bitmap.createBitmap(m.cols(), m.rows(),  Bitmap.Config.ARGB_8888);
Imgproc.cvtColor(m, m, Imgproc.COLOR_BGR2RGB); // Images are natively in BGR color space in opencv. To show it properly in android project, convert the color space to RGB
Utils.matToBitmap(b, bm);
image_view.setImageBitmap(bm);

You can show an image wherever it is. 您可以在任何地方显示图像。

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

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