I am working on an application with Java that corrects the perspective (also called keystoning). To do this, I am using Bytedeco's JavaCV. By referring to documentations and several other websites and manuals online, I tried to do this by using two OpenCV methods, warpPerspective
and cvGetPerspectiveTransform
. More specifically, this is my code:
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();
}
If I execute that code, the console gives me an "OpenCV Error: Bad argument (Unknown array type) in cv::cvarrToMat, file src\matrix.cpp, line 880", and, one of these:
#
# 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.
#
However, I know that mona-lisa.jpg
is being read properly because if I skip all the mmat
process then it renders the original image correctly.
I am trying to achieve something similar to this.
Any thoughts?
Isn't this supposed to store the result in a different image (img2)?
cvWarpPerspective(img, img, mmat);
Also about the crash - it's a long issue that someone suggested it has to do with scoping the variables. Maybe you can check the latest innovations
User contributions licensed under CC BY-SA 3.0