简体   繁体   English

JavaCV:无论我传递什么,cvLoadImage都返回null

[英]JavaCV: cvLoadImage returns null no matter what I pass it

I'm on OS X 10.7.1. 我在OS X 10.7.1上。 I've downloaded the latest JavaCV binaries, and built OpenCV from a current subversion checkout. 我已经下载了最新的JavaCV二进制文件,并从当前的subversion checkout构建了OpenCV。 The cvLoadImage() function returns null, no matter what I pass it. 无论我传递什么,cvLoadImage()函数都返回null。 I have verified that I am passing it a valid path to a valid jpg image. 我已经验证我将它传递给有效的jpg图像的有效路径。 Other JavaCV functions seem to return reasonable values, but since I can't load images, I can't really check. 其他JavaCV函数似乎返回合理的值,但由于我无法加载图像,我无法真正检查。

I think I may have an error somewhere, but I'm not familiar with how JavaCV reports errors, so I can't check. 我想我可能在某个地方有错误,但我不熟悉JavaCV如何报告错误,所以我无法检查。

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). 编辑:我可以验证整个JavaCV安装是否有效和运行,因为如果我使用Java的ImageIO加载图像,它可以工作,我可以随后对加载的图像进行操作,并保存图像(再次,通过ImageIO) 。 SSCE follows: SSCE如下:

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. 由于我可以通过ImageIO使其工作,我不再过分担心这个错误,但解决它可能对使用JavaCV的其他人有用。

OpenCV only works well with ASCII filenames. OpenCV仅适用于ASCII文件名。 If you have i18n characters in the path, it may very well choke. 如果你在路径中有i18n字符,它可能会很好地阻塞。 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. 此外,目前,JavaCV将所有String对象映射到UTF-8,并且看起来Mac OS X默认情况下不使用UTF-8。

So, if i18n is important to your application, keep on using ImageIO... 因此,如果i18n对您的应用程序很重要,请继续使用ImageIO ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM