关于#opencv#的问题:程序包不存在

Android Studio报错:程序包不存在

在OpenCV作为module导入后,一个明明存在的包,它一直报错说不存在,清内存也不好使

img

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 你可以看下这个问题的回答https://ask.csdn.net/questions/211986
  • 你也可以参考下这篇文章:Android Studio使用OpenCV进行图像基本处理
  • 除此之外, 这篇博客: Android Studio OpenCV环境的搭建中的 图像处理参考代码 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:

    在sdk–》samples下面得到源码都可以拿来测试的,能成功运行即说明环境配置完成。

    MainActivity.java文件

    package com.example.test;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.ImageView;
    
    import org.opencv.android.OpenCVLoader;
    import org.opencv.android.Utils;
    import org.opencv.core.Mat;
    import org.opencv.imgproc.Imgproc;
    
    public class MainActivity extends AppCompatActivity {
        static {
            if(!OpenCVLoader.initDebug())
            {
                Log.d("opencv","初始化失败");
            }
        }
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            ImageView imgHuaishi = (ImageView)findViewById(R.id.img_huaishi);
    
            Mat rgbMat = new Mat();
            Mat grayMat = new Mat();
            Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.face);
            Bitmap grayBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), Bitmap.Config.RGB_565);
            Utils.bitmapToMat(srcBitmap, rgbMat);//convert original bitmap to Mat, R G B.
            Imgproc.cvtColor(rgbMat, grayMat, Imgproc.COLOR_RGB2GRAY);//rgbMat to gray grayMat
            Utils.matToBitmap(grayMat, grayBitmap); //convert mat to bitmap
            imgHuaishi.setImageBitmap(grayBitmap);
            Log.i("main", "procSrc2Gray sucess...");
    
        }
    }
    

    布局文件

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:text="dddddd" />
        <ImageView
            android:id="@+id/img_huaishi"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/face"
            android:layout_centerInParent="true"/>
        <Button
            android:id="@+id/btn_gray_process"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/img_huaishi"
            android:layout_centerHorizontal="true"
            android:text="灰度化"/>"
    
    </RelativeLayout>
    

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^

这个

img


你在build.gradle中引用了吗?