[OpenCV4Android] modifying frame(puttext, rectangle ... etc) not working on onCameraFrame
Hello.
I'm a student who is trying to create a program which creates threshold image(using inrange, for use in color blob tracking)
However, I'm stuck with displaying the threshold image on JavaCameraView(for testing purposes).
According to other example and documentations, it seems that modifying OnCameraFrame(CvCameraViewFrame inputFrame)'s inputFrame.rgba() changes the displayed frame. However, I cannot see the modifications I made to the given frame(in the code below, it's mRgba in OnCameraFrame)
I tried to do the following
input text overlay to the frame using puttext
make the frame to be gray using Imgproc.cvtcolor
tried to make thresholdimage using processImage(created inside the code)
None of them change the frame displayed.
I hope to see why the modifications don't work.
PS. The Phone I used was Galaxy S4 LTE-A SK Telecom (SHV-E330S) with OpenCV 2.4.6
PPS. Same thing happens in Nexus S with CM10
package com.example.opencvtrialexample;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.imgproc.Imgproc;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.Menu;
import android.view.SurfaceView;
import android.view.WindowManager;
import android.widget.ImageView;
public class MainActivity extends Activity implements CvCameraViewListener2{
private static final String TAG="MyActivity_OpenCVTest";
private CameraBridgeViewBase mOpenCvCameraView;
private int[][] pointArray=new int[5][2];
private final Scalar HSV1=new Scalar(20,100,100);
private final Scalar HSV2=new Scalar(100,255,255);
//OpenCV Initialization
private BaseLoaderCallback mLoaderCallback=new BaseLoaderCallback(this){
public void onManagerConnected(int status){
switch(status){
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG,"OpenCV loaded Successfully");
mOpenCvCameraView.enableView();
}break;
default:
{
super.onManagerConnected(status);
}break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG,"called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mOpenCvCameraView=(CameraBridgeViewBase)findViewById(R.id.HelloOpenCvView);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
//mOpenCvCameraView.setCvCameraViewListener((CvCameraViewListener2) this);
}
public void onPause(){
super.onPause();
if(mOpenCvCameraView!=null)
mOpenCvCameraView.disableView();
}
public void onDestroy(){
super.onDestroy();
if(mOpenCvCameraView!=null)
mOpenCvCameraView.disableView();
}
public void onResume(){
super.onResume();
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6,this,mLoaderCallback);
}
public void onCameraViewStarted(int width, int height){
}
public void onCameraViewStopped(){
}
public Mat onCameraFrame(CvCameraViewFrame inputFrame){//**This is where Problem Happens**
Mat mRgba=inputFrame.rgba();
Mat mProc=processImage(mRgba);
//Not working puttext
Core.putText(mRgba, "=====TEST=====2013.09.15", new Point(100, 500), 3, 1, new Scalar(255, 0, 0, 255), 2);
//replacing mRgba with mProc
Imgproc.cvtColor(mRgba, mRgba, Imgproc.COLOR_RGBA2GRAY);
Imgproc.cvtColor(mRgba, mRgba, Imgproc.COLOR_GRAY2RGBA);
//temporarily disabled to test whether puttext work
//mProc.copyTo(mRgba);
return mRgba;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is ...
NOTE : I just discovered that i converted(I don't know why...) setCvCameraViewListener to comment(//). After reviving that line, it works very well. Ah! My precious 3 hours!