ActivityThread:源未找到 [英] ActivityThread:source not found

查看:179
本文介绍了ActivityThread:源未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的深化发展Android应用程序来比较两个静止图像。
但是,当Itried调试项目,我曾在ActivityThread没有找到源头。
这里是我的code

I am developping an android application to compare two still images. But when Itried to debug the project I had source not found in ActivityThread. here is my code

查找类

 package com.example.testmatching;

 import java.util.LinkedList;
 import java.util.List;

 import org.opencv.calib3d.Calib3d;
 import org.opencv.core.Core;
 import org.opencv.core.CvType;
 import org.opencv.core.Mat;
 import org.opencv.core.MatOfByte;
 import org.opencv.core.MatOfDMatch;
 import org.opencv.core.MatOfKeyPoint;
 import org.opencv.core.MatOfPoint2f;
 import org.opencv.core.Point;
 import org.opencv.core.Scalar;
 import org.opencv.features2d.DMatch;
 import org.opencv.features2d.DescriptorExtractor;
 import org.opencv.features2d.DescriptorMatcher;
 import org.opencv.features2d.FeatureDetector;
 import org.opencv.features2d.Features2d;
 import org.opencv.features2d.KeyPoint;
 import org.opencv.highgui.Highgui;


import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.RelativeLayout.LayoutParams;
//import org.opencv.core.MatOfPoint;
//import android.view.Menu;

 public class Finder extends Activity {

 @Override

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_comparemain);
}

private static final int CV_LOAD_IMAGE_GRAYSCALE = 0;
private static final String TAG = "OCV::Activity";


//@Override
/*public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.comparemain, menu);
    return true;
}*/


public void run(String pathObject, String pathScene, String pathResult) {

    System.out.println("\nRunning FindObject");


    Mat img_object = new Mat();
    Utils.bitmapToMat(theImage, theImageMat ); // converts some Bitmap to some Mat*/

    Mat img_object = Highgui.imread("C:/work/OpenCV4Android/".concat(pathObject), CV_LOAD_IMAGE_GRAYSCALE); //0 = CV_LOAD_IMAGE_GRAYSCALE
    Mat img_scene = Highgui.imread("C:/work/OpenCV4Android/".concat(pathScene), CV_LOAD_IMAGE_GRAYSCALE);

     if( (img_object.empty()) || (img_scene.empty()) )
      { Log.d(TAG,"failing to read images");
         //System.out.println("images non lues");
      return;}

    FeatureDetector detector = FeatureDetector.create(4); //4 = SURF 

    MatOfKeyPoint keypoints_object = new MatOfKeyPoint();
    MatOfKeyPoint keypoints_scene  = new MatOfKeyPoint();

    detector.detect(img_object, keypoints_object);
    detector.detect(img_scene, keypoints_scene);

    DescriptorExtractor extractor = DescriptorExtractor.create(2); //2 = SURF;

    Mat descriptor_object = new Mat();
    Mat descriptor_scene = new Mat() ;

    extractor.compute(img_object, keypoints_object, descriptor_object);
    extractor.compute(img_scene, keypoints_scene, descriptor_scene);

    DescriptorMatcher matcher = DescriptorMatcher.create(1); // 1 = FLANNBASED
    MatOfDMatch matches = new MatOfDMatch();

    matcher.match(descriptor_object, descriptor_scene, matches);
    List<DMatch> matchesList = matches.toList();

    Double max_dist = 0.0;
    Double min_dist = 100.0;

    for(int i = 0; i < descriptor_object.rows(); i++){
        Double dist = (double) matchesList.get(i).distance;
        if(dist < min_dist) min_dist = dist;
        if(dist > max_dist) max_dist = dist;
    }

    System.out.println("-- Max dist : " + max_dist);
    System.out.println("-- Min dist : " + min_dist);    

    LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
    MatOfDMatch gm = new MatOfDMatch();

    for(int i = 0; i < descriptor_object.rows(); i++){
        if(matchesList.get(i).distance < 3*min_dist){
            good_matches.addLast(matchesList.get(i));
        }
    }

    gm.fromList(good_matches);

    Mat img_matches = new Mat();
    Features2d.drawMatches(
            img_object,
            keypoints_object, 
            img_scene,
            keypoints_scene, 
            gm, 
            img_matches, 
            new Scalar(255,0,0), 
            new Scalar(0,0,255), 
            new MatOfByte(), 
            2);

    LinkedList<Point> objList = new LinkedList<Point>();
    LinkedList<Point> sceneList = new LinkedList<Point>();

    List<KeyPoint> keypoints_objectList = keypoints_object.toList();
    List<KeyPoint> keypoints_sceneList = keypoints_scene.toList();

    for(int i = 0; i<good_matches.size(); i++){
        objList.addLast(keypoints_objectList.get(good_matches.get(i).queryIdx).pt);
        sceneList.addLast(keypoints_sceneList.get(good_matches.get(i).trainIdx).pt);
    }

    MatOfPoint2f obj = new MatOfPoint2f();
    obj.fromList(objList);

    MatOfPoint2f scene = new MatOfPoint2f();

    scene.fromList(sceneList);
    //findHomography sert à trouver la transformation entre les good matches
    Mat hg = Calib3d.findHomography(obj, scene);

    Mat obj_corners = new Mat(4,1,CvType.CV_32FC2);
    Mat scene_corners = new Mat(4,1,CvType.CV_32FC2);

    obj_corners.put(0, 0, new double[] {0,0});
    obj_corners.put(1, 0, new double[] {img_object.cols(),0});
    obj_corners.put(2, 0, new double[] {img_object.cols(),img_object.rows()});
    obj_corners.put(3, 0, new double[] {0,img_object.rows()});
    //obj_corners:input
    Core.perspectiveTransform(obj_corners,scene_corners, hg);

    Core.line(img_matches, new Point(scene_corners.get(0,0)), new Point(scene_corners.get(1,0)), new Scalar(0, 255, 0),4);
    Core.line(img_matches, new Point(scene_corners.get(1,0)), new Point(scene_corners.get(2,0)), new Scalar(0, 255, 0),4);
    Core.line(img_matches, new Point(scene_corners.get(2,0)), new Point(scene_corners.get(3,0)), new Scalar(0, 255, 0),4);
    Core.line(img_matches, new Point(scene_corners.get(3,0)), new Point(scene_corners.get(0,0)), new Scalar(0, 255, 0),4);

    //Sauvegarde du résultat
    System.out.println(String.format("Writing %s", pathResult));
    Boolean bool=false;
    Highgui.imwrite(pathResult, img_matches);
    if (bool == true)
        Log.d(TAG, "SUCCESS writing image to external storage");
      else
        Log.d(TAG, "Fail writing image to external storage");


    ImageView imageView = new ImageView(getApplicationContext());
    //ImageView jpgView = (ImageView)findViewById(R.id.ImageView01);
    LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    /**/Bitmap image = BitmapFactory.decodeFile(pathResult);
    imageView.setImageBitmap(image);
    //RelativeLayout rl = (RelativeLayout) findViewById(R.id.);
    addContentView(imageView, lp);



    }


    }

主要活动

 package com.example.testmatching;
 import  com.example.testmatching.Finder;
 public class COMPAREMainActivity {
public static Finder fn=new Finder();
  public static void main(String[] args) {
   // System.loadLibrary("opencv_java246");
    fn.run("input1.png",  "input2.png","resultat.png");

  }
}   

我把一个断点在该行

I put a breakpoint at that line

Mat img_object = Highgui.imread("C:/work/OpenCV4Android/".concat(pathObject), CV_LOAD_IMAGE_GRAYSCALE);

我要测试是否从该文件夹中读取图像的操作工作与否

I want to test if the operation of reading the image from that folder worked or not

推荐答案

您仿真器将不会从您的计算机参考文件。相反,将文件复制到(使用DDMS)的SD卡,并从那里指,对于例如:

Your emulator will not refer files from your computer. Instead, copy the files to the sdcard(using DDMS) and refer from there, for eg:,

File imgFile = new File(Environment.getExternalStorageDirectory()+"/object.png");// "/mnt/sdcard/object.png"

preFER Environment.getExternalStorageDirectory()不是硬$ C $的cd 到/ mnt / SD卡。因为这可能会在某些设备而异。

Prefer Environment.getExternalStorageDirectory() instead of hard coded "/mnt/sdcard" . Because this may vary in some devices.

这篇关于ActivityThread:源未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆