【问题标题】:JavaCV Perspective Transform Gives ErrorJavaCV 透视变换出错
【发布时间】:2016-04-05 00:27:47
【问题描述】:

我正在使用 Java 开发一个应用程序来纠正透视(也称为梯形校正)。为此,我使用Bytedeco's JavaCV。通过参考documentations 和其他几个websites 和在线手册,我尝试使用两种OpenCV 方法来做到这一点,warpPerspectivecvGetPerspectiveTransform。更具体地说,这是我的代码:

public static void main(String[] args) {
    IplImage img = new IplImage(imread("src/res/mona-lisa.jpg"));
    IplImage img2 = new IplImage(3);

    CvMat mmat = cvCreateMat(3, 3, CV_32FC1);
    CvPoint2D32f c1 = new CvPoint2D32f(4);
    CvPoint2D32f c2 = new CvPoint2D32f(4);

    c1.position(0).put(0, 0);
    c1.position(1).put(400, 0);
    c1.position(2).put(0, 300);
    c1.position(3).put(400, 300);

    c2.position(0).put(0, 0);
    c2.position(1).put(img.width(), 0);
    c2.position(2).put(0, img.height());
    c2.position(3).put(img.width(), img.height());

    mmat = cvGetPerspectiveTransform(c1, c2, mmat);
    cvWarpPerspective(img, img2, mmat);

    cvNamedWindow("Image", 1);
    cvShowImage("Image", img);
    cvWaitKey();
}

如果我执行该代码,控制台会给我一个“OpenCV 错误:cv::cvarrToMat,文件 src\matrix.cpp,第 880 行中的错误参数(未知数组类型)”,并且,其中之一:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_UNCAUGHT_CXX_EXCEPTION (0xe06d7363) at pc=0x00007ffb1e24a1c8, pid=2020, tid=12660
#
# JRE version: Java(TM) SE Runtime Environment (8.0_66-b18) (build 1.8.0_66-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.66-b18 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [KERNELBASE.dll+0x2a1c8]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# ...
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

但是,我知道 mona-lisa.jpg 正在被正确读取,因为如果我跳过所有 mmat 进程,那么它会正确呈现原始图像。

我正在尝试实现类似于this 的目标。

有什么想法吗?

【问题讨论】:

    标签: java opencv javacv


    【解决方案1】:

    这不是应该将结果存储在不同的图像(img2)中吗?

    cvWarpPerspective(img, img, mmat);

    还有关于崩溃 - 这是一个长期的问题,有人建议它与确定变量的范围有关。也许你可以看看最新的创新

    【讨论】:

    • 你能给我更多关于“长期问题”的见解吗?
    • 另外,img, img 是帖子中的错字。它应该是img2。 +1 提醒我这一点。
    • 它的一个已知问题是我的意思,至少当我在 1-2 年前尝试时 - 所以它不会消​​失 - 如果你倾向于 ocv 看到他们的 java 包装器等 - 我不喜欢它不再
    • 我应该使用 ocv 包装器而不是 Jcv 吗?
    • 我想是的,虽然我没有使用最新的包装器,但我怀疑会有问题-
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-06
    • 2013-12-17
    • 2014-09-07
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多