mirror of https://github.com/opencv/opencv.git
Sample renamed to CameraControl; Picture taking added to show camera preview restart.pull/191/head
parent
86f7a357ae
commit
d36f8b9eb3
12 changed files with 83 additions and 40 deletions
@ -1,6 +1,6 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<projectDescription> |
||||
<name>OpenCV Tutorial 5 - Custom camera</name> |
||||
<name>OpenCV Tutorial 5 - Camera Control</name> |
||||
<comment></comment> |
||||
<projects> |
||||
</projects> |
@ -1,4 +1,4 @@ |
||||
set(sample example-tutorial-5-customcamera) |
||||
set(sample example-tutorial-5-cameracontrol) |
||||
|
||||
add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11 ${ANDROID_SDK_TARGET}) |
||||
if(TARGET ${sample}) |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
@ -1,4 +1,4 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<resources> |
||||
<string name="app_name">OCV T5 Custom Camera</string> |
||||
<string name="app_name">OCV T5 Camera Control</string> |
||||
</resources> |
@ -0,0 +1,60 @@ |
||||
package org.opencv.samples.tutorial5; |
||||
|
||||
import java.io.FileOutputStream; |
||||
import java.util.List; |
||||
|
||||
import org.opencv.android.JavaCameraView; |
||||
|
||||
import android.content.Context; |
||||
import android.graphics.Bitmap; |
||||
import android.graphics.BitmapFactory; |
||||
import android.hardware.Camera; |
||||
import android.hardware.Camera.PictureCallback; |
||||
import android.util.AttributeSet; |
||||
import android.util.Log; |
||||
|
||||
public class SampleJavaCameraView extends JavaCameraView { |
||||
|
||||
private static final String TAG = "Sample::SampleJavaCameraView"; |
||||
|
||||
public SampleJavaCameraView(Context context, AttributeSet attrs) { |
||||
super(context, attrs); |
||||
} |
||||
|
||||
public List<String> getEffectList() { |
||||
return mCamera.getParameters().getSupportedColorEffects(); |
||||
} |
||||
|
||||
public String getEffect() { |
||||
return mCamera.getParameters().getColorEffect(); |
||||
} |
||||
|
||||
public void setEffect(String effect) { |
||||
Camera.Parameters params = mCamera.getParameters(); |
||||
params.setColorEffect(effect); |
||||
mCamera.setParameters(params); |
||||
} |
||||
|
||||
public void takePicture(final String fileName) { |
||||
Log.i(TAG, "Tacking picture"); |
||||
PictureCallback callback = new PictureCallback() { |
||||
|
||||
private String mPictureFileName = fileName; |
||||
|
||||
@Override |
||||
public void onPictureTaken(byte[] data, Camera camera) { |
||||
Log.i(TAG, "Saving a bitmap to file"); |
||||
Bitmap picture = BitmapFactory.decodeByteArray(data, 0, data.length); |
||||
try { |
||||
FileOutputStream out = new FileOutputStream(mPictureFileName); |
||||
picture.compress(Bitmap.CompressFormat.JPEG, 90, out); |
||||
mCamera.startPreview(); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
mCamera.takePicture(null, null, callback); |
||||
} |
||||
} |
@ -1,30 +0,0 @@ |
||||
package org.opencv.samples.tutorial5; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.opencv.android.JavaCameraView; |
||||
|
||||
import android.content.Context; |
||||
import android.hardware.Camera; |
||||
import android.util.AttributeSet; |
||||
|
||||
public class CustomJavaCameraView extends JavaCameraView { |
||||
|
||||
public CustomJavaCameraView(Context context, AttributeSet attrs) { |
||||
super(context, attrs); |
||||
} |
||||
|
||||
public List<String> getEffectList() { |
||||
return mCamera.getParameters().getSupportedColorEffects(); |
||||
} |
||||
|
||||
public String getEffect() { |
||||
return mCamera.getParameters().getColorEffect(); |
||||
} |
||||
|
||||
public void setEffect(String effect) { |
||||
Camera.Parameters params = mCamera.getParameters(); |
||||
params.setColorEffect(effect); |
||||
mCamera.setParameters(params); |
||||
} |
||||
} |
Loading…
Reference in new issue