Ask Your Question


asked 2020-04-15 08:47:20 -0600

updated 2020-04-15 20:49:33 -0600

supra56 gravatar image

I'm trying to do a face detecction aplicattion with opencv, and I'm facing a problem with the path of the image that I want to pass as parameter, to test the face detecction. I don't know which directory I have to paste my image, and how can I read it, to pass to the imread. plus, do I need to ask any request like access to the external storage or something?

This is the code of the imread:

            try {

                File imgDir = getDir("imagens_teste", Context.MODE_PRIVATE);
                File cara = new File(imgDir, "cara.jpg");

                Mat imagemColorida = imread(cara.getAbsolutePath());
                Mat imagemCinza = new Mat();

I already tried this:

File root = Environment.getRootDirectory();
            File file = new File(root, "cara.jpg");

            Mat imagemColorida = imread(file.getAbsolutePath());
            Mat imagemCinza = new Mat();

and Mat imagemColorida = imread("src\\main\\imagens_teste\\cara.jpg");

can someone help me?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-04-16 00:56:05 -0600

mvuori gravatar image

Your question is about file access on an undisclosed platform and thus not an OpenCV issue. OpenCV doesn't care where in the file system your image is.

...Apparently this could be on Android. You need to learn where files can be placed on Android, how to refer to those places, and how to set necessary permissions in your app's manifest.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-04-15 08:47:20 -0600

Seen: 506 times

Last updated: Apr 16 '20