我在windows平台上测试了我的程序,运行良好。但是当我尝试在Raspbian, Unix上运行它时,它不会在iplcvLoadimage之后继续运行。
有什么问题吗?
我的代码
mport com.googlecode.javacv.cpp.opencv_core.CvPoint;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import static com.googlecode.javacv.cpp.opencv_core.cvSize;
import static com.googlecode.javacv.cpp.opencv_core.cvZero;
import static com.googlecode.javacv.cpp.opencv_core.cvMinMaxLoc;
import static com.googlecode.javacv.cpp.opencv_core.IPL_DEPTH_32F;
import static com.googlecode.javacv.cpp.opencv_core.cvCreateImage;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvMatchTemplate;
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_TM_SQDIFF;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import org.opencv.core.Core;
public class MatchTemplateTest {
public static HashMap<String,Double> getPatternMatch(String img)
{
ArrayList<String>names=new ArrayList<>();
HashMap<String,Double> MatchMap=new HashMap<>();
File []f=null;
try
{
String path=new File(new File(".").getCanonicalPath()+"/Output"+"/Logo").getAbsolutePath();
f=new File(path).listFiles();
} catch (Exception e) {
}
IplImage src=null;
try {
// this is where the problem is
src= cvLoadImage(img,0);
// can not process further
} catch (Exception e) {
System.out.println("ERROR "+e);
}
如果问题在于读取图像,那么有两种可能性
- 图片不存在,或者图片路径错误。在*nix中,路径用斜杠'/'分隔,例如/home/asharma/data/myimage但在windows中,它用反斜杠分隔,例如C:UserDataMy Image.pgm
- 图片的解码器在库版本中不存在。例如,如果图像是PNG格式,但opencv不是用PNG编译的,那么您无法读取图像。
System.out.println("ERROR "+e);
的输出是什么?