openCv 4 Java HighGui.imshow [英] openCv 4 Java HighGui.imshow

查看:159
本文介绍了openCv 4 Java HighGui.imshow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python方式中,加载和显示图像非常简单.

In the python way, loading and displaying images is quite straightforward.

import cv2 




image = cv2.imread("path/to/image")
cv2.imshow("test window", image)
cv2.waitKey(0) # any key press will close the window and stop the program

在java中,它看起来像这样.

In java, it looks like this.

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.highgui.HighGui;


public class HelloWorld {


  static {
        System.load("/Users/ongyichong/opencv/libopencv_java401.dylib");
    }


  public static void main(String[] args) {

    System.out.println("hello world");

    Mat testFile  = Imgcodecs.imread("/Users/ongyichong/SikuliX/Scripts/NUSivle/0.png");
    HighGui.imshow("test window", testFile);
    HighGui.waitKey(0);
  }

}

我使用的是 opencv 4,但我没有成功地在 java 的 opencv 中实现相同的功能.

Im using opencv 4 and I have not been successful in implementing the same functionality in java's opencv.

HighGui.waitKey(0) 与 python 相比没有按预期工作(任何按键按下都会关闭 python 中的窗口),我必须手动关闭测试窗口"以导致程序停止.

HighGui.waitKey(0) does not work as expected compared to python ( Any key press will close the window in python ) and I have to manually close "test window" to cause the programme to stop.

我在某处读到过,Java 中的 opencv 无法显示图像.但是 HighGui 不提供这个功能吗?我从 java opencv api

I have read somewhere that says that opencv in java is unable to display images. However doesnt HighGui provides this functionality ? I read all the API's from the java opencv api

api 文档在帮助我理解函数的确切作用方面没有那么详细,我只能从 python 猜测它的作用.

The api docs are not as detailed in helping me understand what exactly the function does and i can only guess what it does from python.

推荐答案

waitkey()之后添加System.exit(0);.

这篇关于openCv 4 Java HighGui.imshow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆