Android OpenCV capturing an image from the phone camera. [closed]
I am trying to run an android app that uses openCV. My question is what can i call to capture an image from the camera? Is there a method like "captureAnImageFromYourPhoneCamera()"? I will try to post my code:
package com.kmf.helloopencv;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
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.core.Mat;
import com.kmf.helloopencv.util.SystemUiHider;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
/**
* An implementation of OpenCV to control a lego NXT via an android phone. Work in progress.
* Based off an OpenCV tutorial...
* http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#dev-with-ocv-on-android
*
* And a youtube video with accompanying code...
* https://sites.google.com/site/ghoelzl/nxtcontrolv2
*
* @author Kmf
* @version Alpha
*
*/
public class HelloOpenCvActivity extends Activity implements CvCameraViewListener2 {
/**
* Whether or not the system UI should be auto-hidden after
* {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
*/
private static final boolean AUTO_HIDE = true;
//********** Class fields added *************
private static final String TAG = "MyActivity";
private CameraBridgeViewBase mOpenCvCameraView;
//Random generator = new Random(); //for onCameraFrame experiment
private BluetoothSocket nxtBTsocket = null;
private DataOutputStream nxtDos = null;
public static final String DEFAULT_NXT_NAME = "NXT";
public static final int MOTOR_A_C_STOP = 0;
public static final int MOTOR_A_FORWARD = 1;
public static final int MOTOR_A_BACKWARD = 2;
public static final int MOTOR_C_FORWARD = 3;
public static final int MOTOR_C_BACKWARD = 4;
public static final int TACHOCOUNT_RESET = 8;
public static final int TACHOCOUNT_READ = 9;
public static final int ACTION=10;
public static final int DISCONNECT = 99;
/**
* If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
* user interaction before hiding the system UI.
*/
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
/**
* If set, will toggle the system UI visibility upon interaction. Otherwise,
* will show the system UI visibility upon interaction.
*/
private static final boolean TOGGLE_ON_CLICK = true;
/**
* The flags to pass to {@link SystemUiHider#getInstance}.
*/
private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
/**
* The instance of the {@link SystemUiHider} for this activity.
*/
private SystemUiHider mSystemUiHider;
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.helloopcvlayout);
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.HelloOpenCvView);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
//Inserting createNXTConnection method from NXTControlAndroid.java
try {
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> bondedDevices = btAdapter.getBondedDevices();
BluetoothDevice nxtDevice = null;
for (BluetoothDevice bluetoothDevice : bondedDevices)
{
if (bluetoothDevice.getName().equals(DEFAULT_NXT_NAME)) {
nxtDevice = bluetoothDevice;
break;
}
}
nxtBTsocket = nxtDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
nxtBTsocket.connect();
nxtDos = new DataOutputStream(nxtBTsocket.getOutputStream());
} catch (IOException e) {
Toast toast = Toast.makeText(this, "Problem at creating a connection", Toast.LENGTH_SHORT);
toast.show();
}
}
@Override
public void onPause()
{
super.onPause ...
whaaa, wall of code again. do you really need bluetooth/nfc code here ?
please strip it to the essential
Try "Camera control" tutorial (http://opencv.org/platforms/android/opencv4android-samples.html).