**
- Answer: when working with openCv always use relative path.
**
When I try and read a txt file that is in the same directory as my png file I'm successful
Hey, I'm trying to read an image using OpenCv in my Java app, I'm using java 17(just updated today from java 8) and openCv 453. In the picture you could see the path for the image named src and image named mask and the returned Mat I get from the function imread of imageCodecs.
When I use the File.exists method on my path it returns false. My path Is correct I just copy and paste it from the folder where the file is, how can I get a more accurate path?
Actual code:
public class main
{
public static void main(String[] args)
{
try
{
String path = "C:\\Users\\theit\\OneDrive\\שולחן העבודה\\Hole_Filling_Lightricks\\Lenna.png";
String mask = "C:\\Users\\theit\\OneDrive\\שולחן העבודה\\Hole_Filling_Lightricks\\Mask.png";
int z = Integer.parseInt(args[2]);
float eps = Float.parseFloat(args[3]);
int connectivity = Integer.parseInt(args[4]);
if(connectivity != 4 && connectivity != 8)
throw new Exception("Connectivity type is not 4 or 8");
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
Imgcodecs imageCodecs = new Imgcodecs();
Mat src = imageCodecs.imread(path, Imgcodecs.IMREAD_GRAYSCALE);
int rows = src.rows();
int cols = src.cols();
Mat imageMask = imageCodecs.imread(mask);
}
catch (Exception e)
{
System.out.println(e.getMessage());
System.exit(1);
}
}
}
path = C:\Users\theit\OneDrive\שולחןהעבודה\Hole_Filling_Lightricks\Lenna.png
CurrentWorkingPath = C:\Users\theit\OneDrive\שולחן העבודה\Hole_Filling_Lightricks
How can I solve this problem?