javacvでBOWモデルを実装するアプリを開発しています。
元のコードは c++ で書かれています
ファーストクラス :
public class BOW {
final String trainingData ="";
final String testData="";
int dictionarySize = 500;
// TermCriteria tc(CV_TERMCRIT_ITER, 10, 0.001);
int retries = 1;
int flags = CV_KMEANS_USE_INITIAL_LABELS;
CvTermCriteria termcrit ;
BOWKMeansTrainer bMeansTrainer ;
BOWImgDescriptorExtractor bDescriptorExtractor;
FeatureDetector featureDetector;
DescriptorExtractor descriptorExtractor;
DescriptorMatcher descriptorMatcher;
public BOWKMeansTrainer getbMeansTrainer() {
return bMeansTrainer;
}
public void setbMeansTrainer(BOWKMeansTrainer bMeansTrainer) {
this.bMeansTrainer = bMeansTrainer;
}
public BOWImgDescriptorExtractor getbDescriptorExtractor() {
return bDescriptorExtractor;
}
public void setbDescriptorExtractor(
BOWImgDescriptorExtractor bDescriptorExtractor) {
this.bDescriptorExtractor = bDescriptorExtractor;
}
public FeatureDetector getFeatureDetector() {
return featureDetector;
}
public void setFeatureDetector(FeatureDetector featureDetector) {
this.featureDetector = featureDetector;
}
public DescriptorExtractor getDescriptorExtractor() {
return descriptorExtractor;
}
public void setDescriptorExtractor(DescriptorExtractor descriptorExtractor) {
this.descriptorExtractor = descriptorExtractor;
}
public DescriptorMatcher getDescriptorMatcher() {
return descriptorMatcher;
}
public void setDescriptorMatcher(DescriptorMatcher descriptorMatcher) {
this.descriptorMatcher = descriptorMatcher;
}
public BOW() {
super();
try {
featureDetector = FeatureDetector.create("SIFT");
descriptorExtractor=DescriptorExtractor.create("SIFT");
descriptorMatcher= DescriptorMatcher.create("FlannBased");
termcrit = new CvTermCriteria(CV_TERMCRIT_ITER, 10, 0.001);
bMeansTrainer = new BOWKMeansTrainer(dictionarySize, termcrit , retries, flags);
bDescriptorExtractor = new BOWImgDescriptorExtractor( descriptorExtractor, descriptorMatcher);
} catch (Exception e) {
e.getStackTrace();
}
}
public void extractTrainingVocabulary (String baseurl )
{
File dir = new File(baseurl);
for (File child : dir.listFiles())
{
if (child.isDirectory())
{
System.out.println("Processing directory"+child.getAbsolutePath());
extractTrainingVocabulary(child.getName());
}
else
{
if (child.getName().contains(".jpg"))
{
System.out.println("Processing file" + child.getName());
final CvMat image = cvLoadImageM(child.getName());
if (!image.empty())
{
KeyPoint keypoints = new KeyPoint(); // a verifier
featureDetector.detect(image, keypoints, null);
if (keypoints.isNull())
{
System.out.println("Warning: Could not find key points in image: "+
child.getName()
);
}
else
{
CvMat featurs = new CvMat() ; //
descriptorExtractor.compute(image, keypoints, featurs);
bMeansTrainer.add(featurs);
}
}
else
{
System.out.println("Warning: Could not read image: "+ child.getName());
}
}
}
}
}
public void extractBOWDescriptor (String baseurl , CvMat descriptors )
{
File dir = new File(baseurl);
for (File child : dir.listFiles())
{
if (child.isDirectory())
{
System.out.println("Processing directory"+child.getAbsolutePath());
extractBOWDescriptor(child.getName(), descriptors);
}
else
{
if (child.getName().contains(".jpg"))
{
System.out.println("Processing file" + child.getName());
final CvMat image = cvLoadImageM(child.getName());
if (!image.empty())
{
KeyPoint keypoints = new KeyPoint(); // a verifier
featureDetector.detect(image, keypoints, null);
if (keypoints.isNull())
{
System.out.println("Warning: Could not find key points in image: "+
child.getName()
);
}
else
{
CvMat BoWdescriptors = new CvMat() ; //
bDescriptorExtractor.compute(image, keypoints, BoWdescriptors, null, null);
descriptors.put(descriptors);
// float label=Float.parseFloat(child.getName());
// labels.put(label);
}
}
else
{
System.out.println("Warning: Could not read image: "+ child.getName());
}
}
}
}
}
}
メインクラス:
package pack;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("ppppppp");
String trainingDatapath="bowdemo\\data\\train";
String evalDatapath="bowdemo\\data\\evam";
BOW bow = null;
try {
bow = new BOW();
}
catch (Exception e) {
e.getStackTrace();
}
bow.extractTrainingVocabulary(trainingDatapath);
// MatVector descriptos = bow.getbMeansTrainer().getDescriptors();
CvMat dictionnary = bow.getbMeansTrainer().cluster();
bow.getbDescriptorExtractor().setVocabulary(dictionnary);
CvMat evalData = new CvMat(bow.dictionarySize);
bow.extractBOWDescriptor(evalDatapath, evalData);
}
}
実行:
A fatal error has been detected by the Java Runtime Environment:
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7350b1f2, pid=6900, tid=3984
JRE version: Java(TM) SE Runtime Environment (7.0_45-b18) (build 1.7.0_45-b18)
Java VM: Java HotSpot(TM) Client VM (24.45-b08 mixed mode, sharing windows-x86 )
Problematic frame:
C [MSVCR90.dll+0x3b1f2]
Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
An error report file with more information is saved as:
C:\Users\Desktop\workspaceJAVACV\demo\hs_err_pid6900.log
If you would like to submit a bug report, please visit:
http://bugreport.sun.com/bugreport/crash.jsp
The crash happened outside the Java Virtual Machine in native code.
See problematic frame for where to report the bug.