Issue
I need to create four arrow (up, down, left and right) and put them on frame in real time.I am doing some work with real time image processing and based on the results of function i need to show the arrow in real time on frame. After getting a frame from:
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;
}
It call async task to do the method recognize and set which arrow need to be displayed.For now it return 1 if started frame and other frames are the same.I need to know how to make an arrow and display it on the frame.I will later make an algorithm to determent for direction so lets assume when return is 1 i need to display up arrow in the frame. My asynctask is:
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();
}
}
The method recognize is:
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;
}
Basically it should look like this:
If there is any code missing that helps, let me know and I add it.
Solution
As a solution - draw arrows in Adobe After Effects and use this AirBnB library to implement it
Answered By - Artem
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.