Ask Your Question

riothamus's profile - activity

2014-07-29 13:51:33 -0600 commented question OpenCV Java Ubuntu UnsatisfiedLinkError

I'm seeing the same thing on 2.4.9.0 with scala 2.11.

I did manage to get compiled code to load it, however:

import org.opencv.core.Core
import org.opencv.core.Mat
import org.opencv.core.CvType
import org.opencv.core.Scalar

object SimpleSample {
  def main(args: Array[String]) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    val m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0));
  }
}

$ scala -cp /usr/local/Cellar/opencv/2.4.9//share/OpenCV/java/opencv-249.jar:. 
-Djava.library.path=/usr/local/Cellar/opencv/2.4.9//share/OpenCV/java/ SimpleSample

But not in the repl :(.

2013-05-11 05:11:09 -0600 received badge  Necromancer (source)
2013-04-30 12:45:44 -0600 answered a question Passing Bitmap to JNI

I've solved this by ensuring a buffered image is of type BufferedImage.TYPE_3BYTE_BGR), converting to a byte array, and then copying into the aligned memory in JNI. Code samples below.

Scala part

(Conversion to java should be easy)

// converts an image to BufferedImage.TYPE_3BYTE_BGR
def convertType(img: BufferedImage): BufferedImage = {
    val convertedImg = new BufferedImage(img.getWidth, img.getHeight, BufferedImage.TYPE_3BYTE_BGR)
    convertedImg.getGraphics.drawImage(img, 0, 0, null)
    convertedImg
  }

JNI Part

IplImage* rgbJbyteToIpl(const int width, const int height, const jbyte* const img) {
    int j, channels = 3;
    IplImage * rv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
    // IplImage data is aligned for SIMD instructions.
    // Copy each row individually.
    for (j = 0; j < height; j++) {
        memcpy((void*) &(rv->imageData[(rv->widthStep) * j]), (void*) &(img[j * width * channels]), width * channels);
    }
    return 0;
}
2013-04-29 15:46:17 -0600 commented question Error handling in C

Writing a wrapper is possible, but I'd rather not: 1) modify opencv -or- 2) Write the software in c++

Background: I'm writing an image processing webservice in C. If opencv encounters an error, I'd like to catch it and return an appropriate response via http to the user. As opencv is currently implemented, the program terminates on error.

2013-04-22 19:56:36 -0600 commented question Error handling in C

I don't want to restart the application, nor continue as if nothing happened (that would be an unstable state).

A simple example would be a function that returns 1 if opencv encounters an error, and 0 otherwise.

2013-04-22 10:29:16 -0600 asked a question Error handling in C

I am developing in C using opencv 2.4.5 and need to gracefully handle run-time errors. The default behavior for opencv is to print an error and terminate the application. I'd like to not terminate the application.

In previous versions of the library, this could be changed using cvSetErrorMode, which has been deprecated.

Given that the current error handling is done by throwing a exception in C++, how are we to gracefully handle errors in C, which does not support exceptions?