Ask Your Question
0

SOLVED The method putText(Mat, String, Point, int, int, Scaler) is undefined for the type Imgproc

asked 2018-03-31 11:12:05 -0600

Marko5280 gravatar image

updated 2018-04-04 10:05:47 -0600

Eclipse IDE for JAVA Developers: Version: Oxygen.3 Release (4.7.3)

JRE System Library [JavaSE-1.7]

OpenCV 3.4.0

The original sample "Smoothing Images" C++ script is here:

The original sample "Smoothing Images" Java script is here:

And

The original sample "Smoothing Images" Python script is here:

I have read about the above software and have those versions. I have run the sample C++ script of "Smoothing Images" and it works fine. Now I am trying to run the Java script. But, I get the error message

“The method putText(Mat, String, Point, int, int, Scaler) is undefined for the type Imgproc”

What am I doing wrong?

I have gutted the original Java script but, left the code causing the error.

The offending code follows:

package openCV_340_PACKAGE;

import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;


public class Smoothing_Images2 {
    public static void main(String[] args) {
        // Load the native library.
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat src = new Mat(), dst = new Mat();
        dst = Mat.zeros(src.size(), src.type());
        Imgproc.putText(src, "Original Image",
                new Point(src.cols() / 4, src.rows() / 2),
                Core.FONT_HERSHEY_COMPLEX, 1, new Scalar(255, 255, 255)); 
    }
}

EDIT ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I have no training in Java or OpenCV. That is why I rely on the sample scripts so much. I would expect that the sample scripts would run as is. That is the case with C++ but, not with Java. I have read your message. Notwithstanding . . .

I HAVE run my code snippet and I get the following possible errors . . .

From Intelli-sense On line 26:

Imgproc.putText(src, "Original Image”, new Point(src.cols() / 4, src.rows() / 2),
Core.FONT_HERSHEY_COMPLEX, 1, new Scalar (255, 255, 255));

The error about putText

The method putText(Mat, String, Point, int, int, Scaler) is undefined for the type Imgproc

Also: Is the possible error about POINT. With three options for the import of Point . . .

Import ‘Point’ (java.awt)
Import ‘Point’ (lejos.robotics.geometry) and
Import ‘Point’ (org.opencv.core)

From execution A possible error on execution is again about Point . . .

Exception in thread "main" java.lang.Error: Unresolved compilation problem: Point cannot be resolved to a type at openCV_340_PACKAGE.Smoothing_Images2.main(Smoothing_Images2.java:26)

For some unknown reason, I cannot run your snippet but, Intelli-sense finds an error at Improc.putText! You have obviously run a snippet to completion and shown the results. My current snippet that I am trying to run is

package openCV_340_PACKAGE;

import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.core.Point;


public class berak {

Mat src = new Mat(400,400,16,Scalar.all(127));

Imgproc.putText
        (src,
        "The Image",
        new org.opencv.core.Point( src.cols()/5,
            src.rows()/3),
        Core.FONT_HERSHEY_COMPLEX,
        1,
        new Scalar(255, 255, 255));
}

Note: I cannot find org.opencv.Imgproc.putText

Please post your entire snippet including the imports.

edit retag flag offensive close merge delete

Comments

you obviously did not try to run the code above (it does not reproduce the error)

berak gravatar imageberak ( 2018-04-01 02:53:13 -0600 )edit

2 answers

Sort by » oldest newest most voted
2

answered 2018-04-04 10:03:53 -0600

Marko5280 gravatar image

SOLVED

I have re-downloaded the sample Java script “Smoothing Samples” and run it successfully. It has been trimmed down to the few pertinent lines of code making sure that it executed successfully with each trim. I don't receive the error message. My new code snippet is as follows:

package openCV_340_PACKAGE;

import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgproc.Imgproc;

public class Smoothing_Images_Test_Case {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat src;
        src = new Mat(400,400,16,Scalar.all(127));
        Imgproc.putText(src ,
                    "This Image" ,
                    new Point( src.cols()/4 , src.rows()/2 ) ,
                    Core.FONT_HERSHEY_COMPLEX ,
                    1 ,
                    new Scalar(255, 255, 255)) ;
        HighGui.imshow( "This Frame", src );
        HighGui.waitKey( 1500 );
        System.exit(0);
        }
}

C:\fakepath\This image.png

edit flag offensive delete link more

Comments

1

Very poetic!

sjhalayka gravatar imagesjhalayka ( 2018-04-04 10:14:48 -0600 )edit
1

answered 2018-04-01 02:48:08 -0600

berak gravatar image

there are 2 problems:

  1. the Mat you draw to needs to have a size and a type, a simple new Mat() won't do.
  2. if you import java.awt classes, there will be ambiguities for things like Point, Rect, List (remember that ?) and such, you need to explicitly specify, what you mean:


Mat ocv = new Mat(400,400,16,Scalar.all(127));
Imgproc.putText(ocv, "Original Image",
                new org.opencv.core.Point(ocv.cols() / 4, ocv.rows() / 2),
                Core.FONT_HERSHEY_COMPLEX, 1, new Scalar(255, 255, 255));

image description

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-03-31 11:12:05 -0600

Seen: 4,715 times

Last updated: Apr 04 '18