Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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

JRE System Library [JavaSE-1.7]

OpenCV 3.4.0

I have read about the above software and have those versions. I have run the sample script "Smoothing Images" in C++ and it works fine. Now I am trying to run the script in Java. But, I get the error message “The method putText(Mat, String, Point, int, int, Scaler) is undefined for the type Imgproc”

The sample "Smoothing Images" Java script follows.

What am I doing wrong?

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

class SmoothingRun {

    ///  Global Variables
    int DELAY_CAPTION = 1500;
    int DELAY_BLUR = 100;
    int MAX_KERNEL_LENGTH = 31;

    Mat src = new Mat(), dst = new Mat();
    String windowName = "Filter Demo 1";

    public void run(String[] args) {

        String filename = ((args.length > 0) ? args[0] : "../data/lena.jpg");

        src = Imgcodecs.imread(filename, Imgcodecs.IMREAD_COLOR);
        if( src.empty() ) {
            System.out.println("Error opening image");
            System.out.println("Usage: ./Smoothing [image_name -- default ../data/lena.jpg] \n");
            System.exit(-1);
        }

        if( displayCaption( "Original Image" ) != 0 ) { System.exit(0); }

        dst = src.clone();
        if( displayDst( DELAY_CAPTION ) != 0 ) { System.exit(0); }

        /// Applying Homogeneous blur
        if( displayCaption( "Homogeneous Blur" ) != 0 ) { System.exit(0); }

        //! [blur]
        for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
            Imgproc.blur(src, dst, new Size(i, i), new Point(-1, -1));
            displayDst(DELAY_BLUR);
        }
        //! [blur]

        /// Applying Gaussian blur
        if( displayCaption( "Gaussian Blur" ) != 0 ) { System.exit(0); }

        //! [gaussianblur]
        for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
            Imgproc.GaussianBlur(src, dst, new Size(i, i), 0, 0);
            displayDst(DELAY_BLUR);
        }
        //! [gaussianblur]

        /// Applying Median blur
        if( displayCaption( "Median Blur" ) != 0 ) { System.exit(0); }

        //! [medianblur]
        for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
            Imgproc.medianBlur(src, dst, i);
            displayDst(DELAY_BLUR);
        }
        //! [medianblur]

        /// Applying Bilateral Filter
        if( displayCaption( "Bilateral Blur" ) != 0 ) { System.exit(0); }

        //![bilateralfilter]
        for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
            Imgproc.bilateralFilter(src, dst, i, i * 2, i / 2);
            displayDst(DELAY_BLUR);
        }
        //![bilateralfilter]

        /// Done
        displayCaption( "Done!" );

        System.exit(0);
    }

    int displayCaption(String caption) {
        dst = Mat.zeros(src.size(), src.type());
        Imgproc.putText(dst, caption,
                new Point(src.cols() / 4, src.rows() / 2),
                Core.FONT_HERSHEY_COMPLEX, 1, new Scalar(255, 255, 255));

        return displayDst(DELAY_CAPTION);
    }

    int displayDst(int delay) {
        HighGui.imshow( windowName, dst );
        int c = HighGui.waitKey( delay );
        if (c >= 0) { return -1; }
        return 0;
    }
}

public class Smoothing {
    public static void main(String[] args) {
        // Load the native library.
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        new SmoothingRun().run(args);
    }
}

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

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

JRE System Library [JavaSE-1.7]

OpenCV 3.4.0

I have read about the above software and have those versions. I have run the sample script "Smoothing Images" in C++ and it works fine. Now I am trying to run the script in Java. 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?

The sample "Smoothing Images" Java script follows.

What am I doing wrong?

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

class SmoothingRun {

    ///  Global Variables
    int DELAY_CAPTION = 1500;
    int DELAY_BLUR = 100;
    int MAX_KERNEL_LENGTH = 31;

    Mat src = new Mat(), dst = new Mat();
    String windowName = "Filter Demo 1";

    public void run(String[] args) {

        String filename = ((args.length > 0) ? args[0] : "../data/lena.jpg");

        src = Imgcodecs.imread(filename, Imgcodecs.IMREAD_COLOR);
        if( src.empty() ) {
            System.out.println("Error opening image");
            System.out.println("Usage: ./Smoothing [image_name -- default ../data/lena.jpg] \n");
            System.exit(-1);
        }

        if( displayCaption( "Original Image" ) != 0 ) { System.exit(0); }

        dst = src.clone();
        if( displayDst( DELAY_CAPTION ) != 0 ) { System.exit(0); }

        /// Applying Homogeneous blur
        if( displayCaption( "Homogeneous Blur" ) != 0 ) { System.exit(0); }

        //! [blur]
        for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
            Imgproc.blur(src, dst, new Size(i, i), new Point(-1, -1));
            displayDst(DELAY_BLUR);
        }
        //! [blur]

        /// Applying Gaussian blur
        if( displayCaption( "Gaussian Blur" ) != 0 ) { System.exit(0); }

        //! [gaussianblur]
        for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
            Imgproc.GaussianBlur(src, dst, new Size(i, i), 0, 0);
            displayDst(DELAY_BLUR);
        }
        //! [gaussianblur]

        /// Applying Median blur
        if( displayCaption( "Median Blur" ) != 0 ) { System.exit(0); }

        //! [medianblur]
        for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
            Imgproc.medianBlur(src, dst, i);
            displayDst(DELAY_BLUR);
        }
        //! [medianblur]

        /// Applying Bilateral Filter
        if( displayCaption( "Bilateral Blur" ) != 0 ) { System.exit(0); }

        //![bilateralfilter]
        for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
            Imgproc.bilateralFilter(src, dst, i, i * 2, i / 2);
            displayDst(DELAY_BLUR);
        }
        //![bilateralfilter]

        /// Done
        displayCaption( "Done!" );

        System.exit(0);
    }

    int displayCaption(String caption) {
        dst = Mat.zeros(src.size(), src.type());
        Imgproc.putText(dst, caption,
                new Point(src.cols() / 4, src.rows() / 2),
                Core.FONT_HERSHEY_COMPLEX, 1, new Scalar(255, 255, 255));

        return displayDst(DELAY_CAPTION);
    }

    int displayDst(int delay) {
        HighGui.imshow( windowName, dst );
        int c = HighGui.waitKey( delay );
        if (c >= 0) { return -1; }
        return 0;
    }
}

public class Smoothing {
    public static void main(String[] args) {
        // Load the native library.
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        new SmoothingRun().run(args);
    }
}

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

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 script C++ script of "Smoothing Images" in C++ and it works fine. Now I am trying to run the script in Java. Java script. But, I get the error message message

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

What am I doing wrong?

The sample "Smoothing Images" I have gutted the original Java script follows. 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 SmoothingRun Smoothing_Images2 {

    ///  Global Variables
    int DELAY_CAPTION = 1500;
    int DELAY_BLUR = 100;
    int MAX_KERNEL_LENGTH = 31;

    public static void main(String[] args) {
        // Load the native library.
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat src = new Mat(), dst = new Mat();
    String windowName = "Filter Demo 1";

    public void run(String[] args) {

        String filename = ((args.length > 0) ? args[0] : "../data/lena.jpg");

        src = Imgcodecs.imread(filename, Imgcodecs.IMREAD_COLOR);
        if( src.empty() ) {
            System.out.println("Error opening image");
            System.out.println("Usage: ./Smoothing [image_name -- default ../data/lena.jpg] \n");
            System.exit(-1);
        }

        if( displayCaption( "Original Image" ) != 0 ) { System.exit(0); }

        dst = src.clone();
        if( displayDst( DELAY_CAPTION ) != 0 ) { System.exit(0); }

        /// Applying Homogeneous blur
        if( displayCaption( "Homogeneous Blur" ) != 0 ) { System.exit(0); }

        //! [blur]
        for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
            Imgproc.blur(src, dst, new Size(i, i), new Point(-1, -1));
            displayDst(DELAY_BLUR);
        }
        //! [blur]

        /// Applying Gaussian blur
        if( displayCaption( "Gaussian Blur" ) != 0 ) { System.exit(0); }

        //! [gaussianblur]
        for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
            Imgproc.GaussianBlur(src, dst, new Size(i, i), 0, 0);
            displayDst(DELAY_BLUR);
        }
        //! [gaussianblur]

        /// Applying Median blur
        if( displayCaption( "Median Blur" ) != 0 ) { System.exit(0); }

        //! [medianblur]
        for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
            Imgproc.medianBlur(src, dst, i);
            displayDst(DELAY_BLUR);
        }
        //! [medianblur]

        /// Applying Bilateral Filter
        if( displayCaption( "Bilateral Blur" ) != 0 ) { System.exit(0); }

        //![bilateralfilter]
        for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
            Imgproc.bilateralFilter(src, dst, i, i * 2, i / 2);
            displayDst(DELAY_BLUR);
        }
        //![bilateralfilter]

        /// Done
        displayCaption( "Done!" );

        System.exit(0);
    }

    int displayCaption(String caption) {
        dst = Mat.zeros(src.size(), src.type());
        Imgproc.putText(dst, caption,
Imgproc.putText(src, "Original Image",
                new Point(src.cols() / 4, src.rows() / 2),
                Core.FONT_HERSHEY_COMPLEX, 1, new Scalar(255, 255, 255));

        return displayDst(DELAY_CAPTION);
    }

    int displayDst(int delay) {
        HighGui.imshow( windowName, dst );
        int c = HighGui.waitKey( delay );
        if (c >= 0) { return -1; }
        return 0;
    }
}

public class Smoothing {
    public static void main(String[] args) {
        // Load the native library.
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        new SmoothingRun().run(args);
255)); 
    }
}

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

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.

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

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.