我正在使用openCv 3.0.0在android studio上开发相机应用程序,这是我第一次这样做,我遇到了一些问题。但是我有2个问题:1)我想添加一个按钮在前置摄像头和后置摄像头之间切换。但是我似乎找不到切换的方法。
这是我的onCreate方法:
private Camera mCamera;
private CameraPreview mPreview;
private static int number = Camera.CameraInfo.CAMERA_FACING_FRONT;
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.face_detect_surface_view);
// Create an instance of Camera
mCamera = getCameraInstance(number);// This funtion opens the camera
// Create our Preview view and set it as the content of our activity.
mPreview = new CameraPreview(this, number , mCamera);
final FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview);
// Add a listener to the Capture button
ImageButton captureButton = (ImageButton) findViewById(R.id.button_capture);
captureButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Image captured!", Toast.LENGTH_SHORT).show();
// get an image from the camera
mCamera.takePicture(null, null, mPicture);
}
}
);
// Add a listener to the Change button
ImageButton changeButton = (ImageButton) findViewById(R.id.button_change);
changeButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
if (number == Camera.CameraInfo.CAMERA_FACING_FRONT)
number = Camera.CameraInfo.CAMERA_FACING_BACK;
else
number = Camera.CameraInfo.CAMERA_FACING_FRONT;
//HERE SHOULD BE THE STEPS TO SWITCH
Toast.makeText(getApplicationContext(), "Camera changed!", Toast.LENGTH_SHORT).show();
// get an image from the camera
}
}
);
}
2)我想使用openCv在捕获的图像上进行人脸检测,但我不知道是否可能。我在网上找不到任何东西。我已经尝试过openCv 3.0.0中的faceDetect示例,当我使用相机时它可以工作。那是我最初想要做的,但是在更改布局以包含框架布局而不是org.opencv.android.JavaCameraView之后,它不再起作用。所以,如果有人知道为什么我会非常感激。
所有* CameraView类都具有disableView和enableView方法。您需要禁用视图,设置View对象的mCameraIndex字段,然后再次启用视图。mCameraView是受保护的方法,因此唯一的解决方案是实现视图子类和设置器/获取器。有关更多详细信息,请参见tutorial-3示例。
<org.opencv.android.NativeCameraView
android:id="@+id/tutorial1_activity_native_surface_view"
android:layout_width="350px"
android:layout_height="350px"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
opencv:camera_id="front" />
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句