android mat 使用,android-opencv使用matToBitmap / bitmapToMat将mat转换为灰度

这篇博客讲述了作者在Eclipse环境中使用OpenCV库处理Android应用中的图像时遇到的问题。作者想要将Bitmap转换为Mat类型,并进一步将其转化为灰度图像,但尝试的各种方法都没有成功。代码示例显示了作者如何从资源加载Bitmap,然后转换为Mat对象,最后将处理后的Mat对象转回Bitmap显示在ImageView上。然而,在将Mat对象转换为灰度图像的步骤上遇到了困难。
摘要由CSDN通过智能技术生成

我在eclipse中使用了更新的willowgarage opencv库。我想将mat变量转换为灰度,我尝试了我在网上找到的所有东西,但他们并没有为我工作。

这是我的代码

package com.deneme.deneme;

import android.app.Activity;

import android.os.Bundle;

import android.widget.ImageView;

import org.opencv.android.Utils;

import org.opencv.core.Mat;

import org.opencv.imgproc.Imgproc;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

public class main extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

ImageView img=(ImageView) findViewById(R.id.pic);

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.p26);

Mat imgToProcess=Utils.bitmapToMat(bmp);

//******

//right here I need to convert this imgToProcess to grayscale for future opencv processes

//******

Bitmap bmpOut = Bitmap.createBitmap(imgToProcess.cols(), imgToProcess.rows(), Bitmap.Config.ARGB_8888);

Utils.matToBitmap(imgToProcess, bmpOut);

img.setImageBitmap(bmpOut);

}}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值