图片轮廓处理,javacv运行出现问题,求大神指点
本帖最后由 bianxiaoying11 于 2014-03-10 16:43:04 编辑
import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.CanvasFrame;
import static com.googlecode.javacpp.Loader.*;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import java.io.File;
import javax.swing.JFileChooser;
public class Ishape {
public static void main(String[] args) {
CanvasFrame cnvs=new CanvasFrame("Polygon");
cnvs.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
CvMemStorage storage=CvMemStorage.create();
CvSeq squares = new CvContour();
squares = cvCreateSeq(0, sizeof(CvContour.class), sizeof(CvSeq.class), storage);
JFileChooser f=new JFileChooser();
int result=f.showOpenDialog(f);//show dialog box to choose files
File myfile=null;
String path="";
if(result==0){
myfile=f.getSelectedFile();//selected file taken to myfile
path=myfile.getAbsolutePath();//get the path of the file
}
IplImage src = cvLoadImage(path);//hear path is actual path to image
IplImage gry=cvCreateImage(cvGetSize(src),IPL_DEPTH_8U,1);
cvCvtColor(src, gry, CV_BGR2GRAY);
cvThreshold(gry, gry, 230, 255, CV_THRESH_BINARY_INV);
cvFindContours(gry, storage, squares, Loader.sizeof(CvContour.class), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
CvSeq ss=null;
for (int i=0; i<1; i++)
{
cvDrawContours(gry, squares, CvScalar.WHITE, CV_RGB(248, 18, 18), 1, -1, 8);
ss=cvApproxPoly(squares, sizeof(CvContour.class), storage, CV_POLY_APPROX_DP, 8, 0);
}
IplConvKernel mat=cvCreateStructuringElementEx(7, 7, 3, 3, CV_SHAPE_RECT, null);
cvDilate(gry, gry, mat, CV_C);
cvErode(gry, gry, mat, CV_C);
cnvs.showImage(gry);
}
}
Result
这么一个提取轮廓的代码,总是显示
A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x5d0226df, pid=8764, tid=9200
#
# JRE version: 7.0_09-b05
# Java VM: Java HotSpot(TM) Client VM (23.5-b02 mixed mode windows-x86 )
# Problematic frame:
# C [msvcr100.dll+0x26df] memset+0x5f
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
#
敢问是我环境没配好么,当时配javacv是照教程一步步来的,最后验证环境合格了的,对别的图片进行修改还是可以正常运行的
------解决方案--------------------你配置的是openCV的JAVA版本吧
说实话我没玩过!
但是边缘提取很容易,不一定非得OpenCV
我都是自己写!