开发者

JavaCV: cvLoadImage returns null no matter what I pass it

开发者 https://www.devze.com 2023-04-08 22:35 出处:网络
I\'m on OS X 10.7.1. I\'ve downloaded the latest JavaCV binaries, and built OpenCV from a current subversion checkout.The cvLoadImage() function returns null, no matter what I pass it. I have verified

I'm on OS X 10.7.1. I've downloaded the latest JavaCV binaries, and built OpenCV from a current subversion checkout. The cvLoadImage() function returns null, no matter what I pass it. I have verified that I am passing it a valid path to a valid jpg image. Other JavaCV functions seem to return reasonable开发者_运维知识库 values, but since I can't load images, I can't really check.

I think I may have an error somewhere, but I'm not familiar with how JavaCV reports errors, so I can't check.

EDIT: I can verify that the overall JavaCV installation is valid and functioning, in that if I use Java's ImageIO to load an image, it works and I can subsequently operate on the loaded image, and save an image out (again, through ImageIO). SSCE follows:

import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_objdetect.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;

import java.io.IOException;
import javax.imageio.ImageIO;
import java.io.File;
import java.awt.image.BufferedImage;
import com.googlecode.javacv.cpp.*;
import com.googlecode.javacpp.Loader;

class ImgLoadTest {
  public static void main(String[] args) {
     //comment out EITHER the BufferedImage bit OR the cvLoadImage portion.

     //works
     BufferedImage img =  ImageIO.read(new File(args[0]));
     IplImage origImg = IplImage.createFrom(img); 

     //returns null
     //IplImage origImg = cvLoadImage(args[0]);

     System.out.println("origImg is" + origImg);

  }
}

Since I can make it work via ImageIO, I'm not overly concerned about this bug anymore, but solving it may be of use to others working with JavaCV.


OpenCV only works well with ASCII filenames. If you have i18n characters in the path, it may very well choke. Also, at the moment, JavaCV maps all String objects to UTF-8, and it does not seem like Mac OS X uses UTF-8 by default.

So, if i18n is important to your application, keep on using ImageIO...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号