如何绘制箭头,放入框并实时显示?

时间:2018-09-11 21:43:36

标签: java android android-xml android-drawable

我需要创建四个箭头(向上,向下,向左和向右)并实时放置在框架中。我正在对实时图像进行一些处理,并且根据功能的结果,我需要显示箭头实时实时显示。从以下位置获取框架后:

 public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    mRgba = inputFrame.rgba();
    mGray = inputFrame.gray();
    if(state){

        myTask= new MyTask();
        myTask.execute(mRgba);
        //need to write method to display arrow
        return mRgba;
    }
    return mRgba;
}

它调用异步任务来使方法识别并设置需要显示的箭头。如果开始的帧和其他帧相同,则现在返回1.我需要知道如何制作箭头并将其显示在稍后我将制定一种确定方向的算法,因此让我们假设当return为1时,我需要在框架中显示向上箭头。 我的异步任务是:

class MyTask extends AsyncTask<Mat, Void, Integer> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }

    @Override
    protected Integer doInBackground(Mat... mats) {
        if(!isCancelled())
        return recognize(mats[0]);
        else return 0;
    }

    @Override
    protected void onPostExecute(Integer integer) {
        super.onPostExecute(integer);
        directionOfCamera=integer;
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }
}

方法识别为:

public int recognize(Mat inputFrame) {

    if (startedFrame){

        deskriptor.detect(inputFrame,keypoints1);
        deskriptor.compute(inputFrame,keypoints1,deskriptor1);

        startedFrame=false;
        return 0;
    }

    deskriptor.detect(inputFrame,keypoints2);

    Size size;
    size=keypoints2.size();

    if(size.height!= 0) {
    deskriptor.compute(inputFrame,keypoints2,deskriptor2);

    List<MatOfDMatch> matches = new LinkedList<MatOfDMatch>();

    matcher.knnMatch(deskriptor1, deskriptor2, matches,2);

        //Calculating good match list...
        LinkedList<DMatch> goodMatchesList = new LinkedList<DMatch>();

        for (int i = 0; i < matches.size(); i++) {
            MatOfDMatch matofDMatch = matches.get(i);
            DMatch[] dmatcharray = matofDMatch.toArray();
            DMatch m1 = dmatcharray[0];
            DMatch m2 = dmatcharray[1];

            if (m1.distance <= m2.distance * nndrRatio) {
                goodMatchesList.addLast(m1);

            }
        }

        if (goodMatchesList.size() >= 7) {

            List<KeyPoint> controlKeypointlist = keypoints1.toList();
            List<KeyPoint> liveKeypointlist = keypoints2.toList();

            LinkedList<Point> objectPoints = new LinkedList<>();
            LinkedList<Point> scenePoints = new LinkedList<>();

            for (int i = 0; i < goodMatchesList.size(); i++) {
                objectPoints.addLast(controlKeypointlist.get(goodMatchesList.get(i).queryIdx).pt);
                scenePoints.addLast(liveKeypointlist.get(goodMatchesList.get(i).trainIdx).pt);
            }

            MatOfPoint2f objMatOfPoint2f = new MatOfPoint2f();
            objMatOfPoint2f.fromList(objectPoints);

            MatOfPoint2f scnMatOfPoint2f = new MatOfPoint2f();
            scnMatOfPoint2f.fromList(scenePoints);

            return 1;

        }
    }

    return 0;
}

基本上应该是这样的:

enter image description here

如果缺少帮助的代码,请告诉我并添加。

1 个答案:

答案 0 :(得分:0)

作为解决方案-在Adobe After Effects中绘制箭头 并使用此AirBnB library来实现