如何绘制箭头并实时显示在边框上?
How to draw an arrow,put on frame and display in real time?
我需要创建四个箭头(上、下、左、右)并将它们真实地放在框架上 time.I 我正在做一些实时图像处理工作,并基于我需要的功能的结果在框架上实时显示箭头。从以下位置获取帧后:
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;
}
它调用异步任务来识别和设置需要哪个箭头的方法 displayed.For 现在它 return 1 如果开始帧和其他帧是 same.I 需要知道的如何制作箭头并将其显示在 frame.I 上稍后将制定一个算法来阻止方向,因此让我们假设当 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;
}
基本上应该是这样的:
如果缺少任何有帮助的代码,请告诉我,我会添加。
作为解决方案 - 在 Adobe After Effects 中绘制箭头
并使用这个AirBnB library来实现它
我需要创建四个箭头(上、下、左、右)并将它们真实地放在框架上 time.I 我正在做一些实时图像处理工作,并基于我需要的功能的结果在框架上实时显示箭头。从以下位置获取帧后:
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;
}
它调用异步任务来识别和设置需要哪个箭头的方法 displayed.For 现在它 return 1 如果开始帧和其他帧是 same.I 需要知道的如何制作箭头并将其显示在 frame.I 上稍后将制定一个算法来阻止方向,因此让我们假设当 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;
}
基本上应该是这样的:
如果缺少任何有帮助的代码,请告诉我,我会添加。
作为解决方案 - 在 Adobe After Effects 中绘制箭头 并使用这个AirBnB library来实现它