简体   繁体   English

putText在opencv3.0中不起作用

[英]putText does not work in opencv3.0

import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class Testingopencv 
{

   public static void main(String[] args) 
   {
      System.loadLibrary("opencv_java300");

      Mat src = Imgcodecs.imread("m.jpg");
      Mat temp = new Mat(src.rows(),src.cols(), src.type());

      Imgproc.putText(src, "Edited by me", new Point(src.rows()/2,src.cols()/2),
            Core.FONT_ITALIC, 1.0 ,new  Scalar(255));
      Imgcodecs.imwrite("watermarked.jpg", src);
   }
}

I am trying to use OpenCV 3.0 to make a watermark on a image but there is a problem with putText , I have searched around the internet but there is no solution. 我正在尝试使用OpenCV 3.0在图像上做水印,但是putText出现了问题,我在互联网上进行了搜索,但是没有解决方案。

The error message is: 错误消息是:

The method putText(org.opencv.core.Mat, java.lang.String, org.opencv.core.Point, int, double, org.opencv.core.Scalar) in the type Imgproc is not applicable for the arguments (org.opencv.core.Mat, java.lang.String, java.awt.Point, int, double, org.opencv.core.Scalar) Imgproc类型的方法putText(org.opencv.core.Mat,java.lang.String,org.opencv.core.Point,int,double,org.opencv.core.Scalar)不适用于参数(org .opencv.core.Mat,java.lang.String,java.awt.Point,int,double,org.opencv.core.Scalar)

And the parameters should be correct as the message shown above. 并且参数应该与上面显示的消息一样正确。 How can I solve this? 我该如何解决?

The error message already shows the issue: 错误消息已经显示了问题:

The method putText(org.opencv.core.Mat, java.lang.String, org.opencv.core.Point , int, double, org.opencv.core.Scalar) in the type Imgproc is not applicable for the arguments (org.opencv.core.Mat, java.lang.String, java.awt.Point , int, double, org.opencv.core.Scalar) Imgproc类型的方法putText(org.opencv.core.Mat,java.lang.String, org.opencv.core.Point ,int,double,org.opencv.core.Scalar)不适用于参数(org .opencv.core.Mat,java.lang.String, java.awt.Point ,int,double,org.opencv.core.Scalar)

Be sure to pass to putText the point as org.opencv.core.Point instead of java.awt.Point . 确保将putText传递给org.opencv.core.Point而不是java.awt.Point

This code is working. 该代码有效。

// Draw a bounding box around each face.
        for (Rect rect : faceDetections.toArray())
        {
            Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 255));
            // for crop face
            rectCrop = new Rect(rect.x, rect.y, rect.width, rect.height);   

            Core.putText(image, "Edited by me", new Point(rect.x,rect.y),
                    Core.FONT_HERSHEY_PLAIN, 1.0 ,new  Scalar(0,255,255));
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM