这个范例不一定能跑起来。原因就是依赖库加载的问题。如果libopencv_java.so:
包含其他所有的so功能,上述博文就是对的。
如果不包含,需要一定的加载技巧。
代码范例如下:
package taishan;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
@SuppressWarnings("serial")
public class OpenCVTest
{
public final static String LIB_PATH = "/home/wuxi/eclipse-workspace/OpenCVTest/libs/bin";
private static List getOpenCVFiles(final String dirName)
{
if (dirName == null)
{
return null;
}
File dir = new File(dirName);
if (!dir.exists() || !dir.isDirectory())
{
return null;
}
File[] files = dir.listFiles();
List fileList = new LinkedList();
for (File file : files)
{
String name = file.getName();
if ( name.startsWith("lib") && name.endsWith(".so"))
{
fileList.add(file);
}
}
return fileList;
}
private static void loadNativeOpenCV(final String dirName)
{
List fileList = getOpenCVFiles(dirName);
if (fileList == null || fileList.size() == 0)
{
return;
}
while (fileList.size() > 0)
{
for (int i=0; i 关键的一句就是要正确找到so包。











