本文介绍了转换的Andr​​oid位图OpenCV的垫子和倒退的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想简单地转换为位图,从机器人到了OpenCV的一个垫目标。本主题往往不客气堆栈溢出。例如:

I wanted to simply convert a bitmap from Android to a Mat object for OpenCV. This topic is often adressed on Stack Overflow. For example:

转换垫为位图OpenCV进行Android的;<一href="http://stackoverflow.com/questions/17390289/convert-bitmap-to-mat-after-capture-image-using-android-camera?rq=1">convert位图使用Android摄像头捕获图像之后,太;<一href="http://stackoverflow.com/questions/13900247/templatematching-mattobitmap-opencv-for-android?lq=1">templateMatching mattoBitmap OpenCV的Andr​​oid版

convert Mat to Bitmap Opencv for Android ;convert Bitmap to Mat after capture image using android camera ;templateMatching mattoBitmap opencv for android

甚至有更多的发现。我跟着这个答案instrcutions,但我仍然无法得到的是做了正确的方式。

There is even more to find. I followed the instrcutions in this answers, but I'm still unable to get is done the right way.

最小的code:

//First convert Bitmap to Mat
Mat ImageMat = new Mat ( image.getHeight(), image.getWidth(), CvType.CV_8U, new Scalar(4));
Bitmap myBitmap32 = image.copy(Bitmap.Config.ARGB_8888, true);
Utils.bitmapToMat(myBitmap32, ImageMat);

//Do smth.
Imgproc.cvtColor(ImageMat, ImageMat, Imgproc.COLOR_RGB2GRAY,4);

//Then convert the processed Mat to Bitmap
Bitmap resultBitmap = Bitmap.createBitmap(ImageMat.cols(),  ImageMat.rows(),Bitmap.Config.ARGB_8888);;
Utils.matToBitmap(ImageMat, resultBitmap);

//Set member to the Result Bitmap. This member is displayed in an ImageView
mResult = resultBitmap;

(注:图片是提供给该行的code位图)

(note: image is a Bitmap supplied to this lines of code)

错误:08-07 15:13:59.188:E / AndroidRuntime(2115):致命异常:主要

Errors:08-07 15:13:59.188: E/AndroidRuntime(2115): FATAL EXCEPTION: main

08-07 15:13:59.188:E / AndroidRuntime(2115):java.lang.NoClassDefFoundError的:org.opencv.core.Mat

08-07 15:13:59.188: E/AndroidRuntime(2115): java.lang.NoClassDefFoundError: org.opencv.core.Mat

但我impots是:

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;


//OpenCV
import org.opencv.android.Utils;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;

真的AP preciate任何形式的帮助。由于丹斯

Would really appreciate any sort of help.Thanks DanS

推荐答案

您只能使用OpenCV的做你的工作,它初始化后。所以,你需要初始化这样的:

You only can do your work with OpenCV after it is initialized.So you need to initialize it like that:

  1. 创建一个回调:

  1. Create a Callback:

私人BaseLoaderCallback mOpenCVCallBack =新BaseLoaderCallback(本){    @覆盖    公共无效onManagerConnected(INT状态){        开关(状态){        案例LoaderCallbackInterface.SUCCESS:            //做你的工作/东西在这里            打破;        默认:            super.onManagerConnected(状态);            打破;        }    }};

private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) { @Override public void onManagerConnected(int status) { switch (status) { case LoaderCallbackInterface.SUCCESS: //DO YOUR WORK/STUFF HERE break; default: super.onManagerConnected(status); break; } }};

@覆盖    保护无效onResume(){        super.onResume();        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8,这一点,                mOpenCVCallBack);    }
和多数民众赞成它,我希望它是有益的:D

@Override protected void onResume() { super.onResume(); OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this, mOpenCVCallBack); }
and thats it, i hope it was helpful :D

这篇关于转换的Andr​​oid位图OpenCV的垫子和倒退的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 14:15