android-opencv 使用 matToBitmap/bitmapToMat 将 mat 转换为灰度
我在 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);
}
}
I am using newer opencv library of willowgarage in eclipse. And I want to convert a mat variable into grayscale, I've tried everything I found on the net but they didnt work for me.
Here is my code
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在代码块中添加以下代码:
或者您可以自己访问像素:
Add the following code in your code block:
Or you can access pixels by yourself: