我正在使用Java来修正透视图(也称为梯形失真)。为此,我使用的是Bytedeco's JavaCV。通过在线引用documentations和其他几个websites和手册,我尝试使用两种OpenCV方法warpPerspective
和cvGetPerspectiveTransform
来完成此操作。更具体地说,这是我的代码:
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();
}
如果我执行该代码,控制台会在cv :: cvarrToMat,文件src \ matrix.cpp,第880行中给出一个“OpenCV错误:错误的参数(未知数组类型)”,其中一个:
#
# 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类似的东西。
有什么想法吗?
答案 0 :(得分:1)
这不应该将结果存储在不同的图像中(img2)吗?
cvWarpPerspective(img,img,mmat);
关于崩溃 - 这是一个很长的问题,有人建议它与范围变量有关。也许你可以查看最新的创新