Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java code for reading image instead of getting frame

i am using the native approach but i want the image as input rather than frames , when i run this code its not running the camera as well this is my java code

public class CvNativeActivity extends Activity implements CvCameraViewListener2
{
    private CameraBridgeViewBase mOpenCvCameraView;

    public native int convertNativeGray(int n);

    private final static String TAG = "CvNativeActivity";
    public native int convertNativeGray(long matAddrRgba, long matAddrGray);

    private Mat mRgba;
    private Mat mGray;

    // other part

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) 
    {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {
                    System.loadLibrary("native_activity");// Load Native module
                    Log.i(TAG, "OpenCV loaded successfully");
                    mOpenCvCameraView.enableView();
                } break;
                default:
                {
                    super.onManagerConnected(status);
                } break;
            }
        }
    };

    // some more stuff

    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        mRgba = inputFrame.rgba();
        convertNativeGray(mRgba.getNativeObjAddr(), 
                          mGray.getNativeObjAddr());
        return mGray;
    }
    @Override
    public void onCameraViewStarted(int width, int height) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onCameraViewStopped() {
        // TODO Auto-generated method stub

    }
}
like image 628
AHF Avatar asked Nov 11 '22 09:11

AHF


1 Answers

Have you tried this:

File file= new File(android.os.Environment.getExternalStorageDirectory(),"Your folder");
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath())

Source: Raghunandan

like image 153
Wong Tan Avatar answered Nov 14 '22 21:11

Wong Tan