Primitive man running Java on the command line
I introduced it because I have to use OpenCV at the university graduate research That way Even if I searched now, I had a hard time because most of the stories were in Python and C ++ and there were few stories about java.
I basically obeyed the following sites. Basically, this one is more polite. However, with the latest version (4.4.0), the test code cannot be executed well, so I will write it there. Use OpenCV in Java| JProgramer
It is good to execute the downloaded .exe file and extract it to the C drive, so I created a folder called OpenCV and extracted it there.
Pass through
Although it is a user variable on the reference site, I added it to the system variable. Select "Path" and click [Edit]. At the bottom C:\OpenCV\opencv\build\java\x86 If you just want to use OpenCV in java, you can add this much, and if you use it in Python or Visual Studio, this is not enough. I have VS2017 in it, so I'm passing it through.
The last part is [x86] if java is 32bit, [x64] if java is 64bit Since my machine is 64bit, when I thought it was 64bit and executed the test code (described later), I got an error like "I am 32bit! 64bit program is unreasonable!", So the machine and java bit are not necessarily the same. Does not seem to be limited.
The test code of the reference site gives an error in Ver.4.4.0.
Specifically, the image output class has moved to `ʻimgcodecsinstead of
highgui``.
Test.java
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.imgcodecs.Imgcodecs;
public class Test{
public static void main(String[] args){
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat redImg=new Mat(100,200,CvType.CV_8UC3,new Scalar(0,0,255));
Imgcodecs.imwrite("test.jpg ",redImg);
}
}
The compile command is below ↓
javac -classpath “C:\Saved folder\opencv\build\java\opencv-version.jar” Test.java
this
java -cp .;C:\Saved folder\opencv\build\java\opencv-version.jar Test
When executed with, a bright red JPG image was output (saved) in the same folder.
When you set the classpath
javac Test.java java Test
You can do it with. Please see the reference site for details.
Recommended Posts