Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Convert c++ code to java code

Hi, I need to convert workable example of OpenCV application to the Java code. To be exactly, I'm trying to convert this project https://github.com/ytsutano/bookscan from OpenCV C++ completely to Java.

As Java library I use opencv-245.jar from opencv/build/java folder of OpenCV.

I already found out following transitions from c++ to java:

IplImage => Mat
CvMat => Mat
cvSaveImage => Highgui.imwrite
cvReleaseImage(img) => img.release()
CvCapture capture = cvCreateCameraCapture(0); => VideoCapture capture = new VideoCapture(0);
cvSetCaptureProperty(capture, ...)  => capture.set(...)
Mat src_img = cvQueryFrame(capture); =>  capture.grab(); Mat src_img; capture.retrieve(src_img);
cvCloneImage(src_img); => src_img.clone();
cvGetSize(src_img) => src_img.size();
cvSize(-1, -1) => new Size(-1, -1)
cvPoint(0, 0) => new Point(0, 0)

But there are many other a lot of code that I don't how to write with Java. For example:

imshow("image", im);
cvNamedWindow("Source", 0);
cvResizeWindow("Source", 480, 640);
cvWaitKey(10)
cvShowImage("Source", src_img);
cvCreateMemStorage(0);
cvFindContours(bw_img, storage, contour, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0,0))
cvAdaptiveThreshold(gray_img, bw_img, 128, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV, 31, 8);
cvCvtColor(src_img, gray_img, CV_BGR2GRAY);
cvFindCornerSubPix(src_img, ...)
cvCreateMat(3, 3, CvType.CV_64FC1);

These constants from types_c.h files are also located in unknown places: IPL_DEPTH_8U, CV_ADAPTIVE_THRESH_MEAN_C, CV_RETR_LIST, CV_CHAIN_APPROX_NONE etc.

Following classes seems doesn't exist in Java wrapper: CvPoint2D32f, CvMemStorage, CvSeq.

And all of this is not a complete list.

**So, is there some tool or documentation that can help me in this Java code rewriting? http://docs.opencv.org/java/ is not very helpful. Also, I'd be very grateful if you can answer how to write some of provided lines using Java.

And is it possible to rewrite this using JavaCL (maybe, it'll be faster?)?**

Convert c++ code to java code

Hi, I need to convert workable example of OpenCV application to the Java code. To be exactly, I'm trying to convert this project https://github.com/ytsutano/bookscan from OpenCV C++ completely to Java.

As Java library I use opencv-245.jar from opencv/build/java folder of OpenCV.

I already found out following transitions from c++ to java:

IplImage => Mat
CvMat => Mat
cvSaveImage => Highgui.imwrite
cvReleaseImage(img) => img.release()
CvCapture capture = cvCreateCameraCapture(0); => VideoCapture capture = new VideoCapture(0);
cvSetCaptureProperty(capture, ...)  => capture.set(...)
Mat src_img = cvQueryFrame(capture); =>  capture.grab(); Mat src_img; capture.retrieve(src_img);
cvCloneImage(src_img); => src_img.clone();
cvGetSize(src_img) => src_img.size();
cvSize(-1, -1) => new Size(-1, -1)
cvPoint(0, 0) => new Point(0, 0)

But there are many other a lot of code that I don't how to write with Java. For example:

imshow("image", im);
cvNamedWindow("Source", 0);
cvResizeWindow("Source", 480, 640);
cvWaitKey(10)
cvShowImage("Source", src_img);
cvCreateMemStorage(0);
cvFindContours(bw_img, storage, contour, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(0,0))
cvAdaptiveThreshold(gray_img, bw_img, 128, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV, 31, 8);
cvCvtColor(src_img, gray_img, CV_BGR2GRAY);
cvFindCornerSubPix(src_img, ...)
cvCreateMat(3, 3, CvType.CV_64FC1);

These constants from types_c.h files are also located in unknown places: IPL_DEPTH_8U, CV_ADAPTIVE_THRESH_MEAN_C, CV_RETR_LIST, CV_CHAIN_APPROX_NONE etc.

Following classes seems doesn't exist in Java wrapper: CvPoint2D32f, CvMemStorage, CvSeq.

And all of this is not a complete list.

**So, So, is there some tool or documentation that can help me in this Java code rewriting? http://docs.opencv.org/java/ is not very helpful. Also, I'd be very grateful if you can answer how to write some of provided lines using Java.

Java.

And is it possible to rewrite this using JavaCL (maybe, it'll be faster?)?**faster?)?