Is Java Imgcodecs.imwrite implemented in OpenCV 3.4.0?
I am trying to put an image on the screen with Imgcodecs.imwrite But, I get the error message
OpenCV Error: Unspecified error (could not find a writer for the specified extension) in cv::imwrite_, file C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\imgcodecs\src\loadsave.cpp, line 677 Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\imgcodecs\src\loadsave.cpp:677: error: (-2) could not find a writer for the specified extension in function cv::imwrite_ ] at org.opencv.imgcodecs.Imgcodecs.imwrite_1(Native Method) at org.opencv.imgcodecs.Imgcodecs.imwrite(Imgcodecs.java:197) at myfirstPackage.HelloCV5.main(HelloCV5.java:27)
Other commands work fine, but Imcodecs.imwrite gives me errors about C++ The code follows ...
package myfirstPackage;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
public class HelloCV5 {
public static void main(String[] args){
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat mat = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("mat = " + mat.dump());
System.out.println("mat = " + mat.dump());
System.out.println("Class/Program HelloCV5");
Mat src;
src = Imgcodecs.imread("lena.jpg", Imgcodecs.IMREAD_COLOR);
src = Imgcodecs.imread("lena.jpg", Imgcodecs.IMREAD_COLOR);
System.out.println("Point 1");
Imgcodecs.imwrite( "Window Name Literal", src );
System.out.println("Point 2");
System.out.println("1/27/2018");
}
}
can it be, you misunderstand something simple here ?
imwrite() does not show an image, it writes an image to disk. and for that, a filename extension is needed, like "myimage.png"
to actually display an imge on a gui window, have a look e.g. here
you want something like:
I do not know imgcodecs.imwrite. Imgcodecs.imread reads from disk. So, Imgcodecs.imwrite writing to disk would be consistent. "Smoothing Images" is the example that I am trying to implement. HighGui.imshow used to work in OpenCV 2.XX But, in OpenCV 3.xx there is no HighGui. I am trying to find an OpenCV 3.XX equivalent to the OpenCV 2.xx HighGui imshow. The "Smoothing Images" example works in C++. It is the Java code that has a fault at HighGui.imshow..
again, 3.4 introduced a (sparse) pure java Highgui module, which mocks the previous imshow()/waitKey().
just try it ! (sample works fine for me !)
and, ofc. you have to check:
if (!src.empty())
after loading the image ...I have restarted from the beginning. New workspace. New setup (OpenCV 3.4.0 - Java 8) link. New SmothingImagesClass file. Now I am worse off.? None of the libraries are linked. Except java.awt.Point. Is there something about the install instructions that I am missing?
http://opencv-java-tutorials.readthed...
Interestingly: SmoothingImagesProject/Properties/Source/Native library location: says (None)
ofc?
yea, life is hard, if you're a noob....
" New workspace." -- what does that mean ?
did you try compiling/running with ant, like mentioned here
The smoothingImages sample program has:
import org.opencv.highgui.HighGui;
There is not one of those in the library, however there is an:
org.opencv.highgui.Highgui that I can link to.
Note that the capitalization is different.
HighGui seems absolutely correct