我在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);
} …Run Code Online (Sandbox Code Playgroud) 我只想在c ++项目中显示这个"img1.jpg"图像,使用opencv libs进行未来的处理,但它只显示一个空的灰色窗口.这是什么原因.这段代码有错吗?请帮忙!
这是代码;
Mat img1;
char imagePath[256] = "img1.jpg";
img1 = imread(imagePath, CV_LOAD_IMAGE_GRAYSCALE);
namedWindow("result", 1);
imshow("result", img1);
Run Code Online (Sandbox Code Playgroud)
谢谢...