Ask Your Question
0

Is Java Imgcodecs.imwrite implemented in OpenCV 3.4.0?

asked 2018-01-29 15:30:21 -0600

Marko5280 gravatar image

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");
            }
}
edit retag flag offensive close merge delete

Comments

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:

int displayDst(int delay) {
    HighGui.imshow( windowName, dst );
    int c = HighGui.waitKey( delay );
    if (c >= 0) { return -1; }
    return 0;
}
berak gravatar imageberak ( 2018-01-29 15:48:17 -0600 )edit

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..

int displayDst(int delay) {
        HighGui.imshow( windowName, dst );
        int c = HighGui.waitKey( delay );
        if (c >= 0) { return -1; }
        return 0;
Marko5280 gravatar imageMarko5280 ( 2018-01-30 05:19:35 -0600 )edit

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 ...

berak gravatar imageberak ( 2018-01-30 05:37:46 -0600 )edit

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?

Marko5280 gravatar imageMarko5280 ( 2018-01-30 08:40:59 -0600 )edit

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

berak gravatar imageberak ( 2018-01-30 08:54:39 -0600 )edit

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.

Marko5280 gravatar imageMarko5280 ( 2018-01-30 09:52:00 -0600 )edit

HighGui seems absolutely correct

berak gravatar imageberak ( 2018-01-30 10:06:47 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-01-31 15:58:33 -0600

Marko5280 gravatar image

Should be fixed in "master" branch (by this large patch: #10495). You can get missed files here (rename them and put into the right directory near your sample): https://github.com/opencv/opencv/tree...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-01-29 15:30:21 -0600

Seen: 6,463 times

Last updated: Jan 29 '18