Skip to content

Added screen rotation support to JavaCamera2View amd NativeCameraView. Fixed JavaCamera2View initialization.#24869

Merged
asmorkalov merged 2 commits intoopencv:4.xfrom
alexlyulkov:al/android-camera-view-rotate
Jan 17, 2024
Merged

Added screen rotation support to JavaCamera2View amd NativeCameraView. Fixed JavaCamera2View initialization.#24869
asmorkalov merged 2 commits intoopencv:4.xfrom
alexlyulkov:al/android-camera-view-rotate

Conversation

@alexlyulkov
Copy link
Copy Markdown
Contributor

Added automatic image rotation to JavaCamera2View and NativeCameraView so the video preview was matched with screen orientation.
Fixed double preview initialization bug in JavaCamera2View.
Added proper cameraID parsing to NativeCameraView similar to JavaCameraView

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

}

Log.i(LOGTAG, "Opening camera: " + mCameraID);
manager.openCamera(mCameraID, mStateCallback, mBackgroundHandler);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved camera starting here, because preview size should be defined before camera start

mCaptureSession.close();
mCaptureSession = null;
}
createCameraPreviewSession();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a createCameraPreviewSession call in onOpened camera callback.

@asmorkalov
Copy link
Copy Markdown
Contributor

@alexlyulkov I do not see preview with Pixel8 in Tutorial 4. Just black screen with text status in corner.

@asmorkalov
Copy link
Copy Markdown
Contributor

Tutorial1-Camera-Preview works with all back-ends JavaCameraView, Java2CameraView and NativeCameraView with rotation. Please ignore the previous comment on Tutorial4. The sample does not work without the patch. It should be fixed separately.

Comment on lines +129 to +131
android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(localCameraIndex, info);
int frameRotation = getFrameRotation(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you can re-use CameraInfo from cameras iteration when camera is selected.

Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@asmorkalov asmorkalov merged commit bfad61f into opencv:4.x Jan 17, 2024
@asmorkalov asmorkalov mentioned this pull request Jan 23, 2024
JStech pushed a commit to JStech/opencv that referenced this pull request Jan 28, 2024
…ew-rotate

Added screen rotation support to JavaCamera2View amd NativeCameraView. Fixed JavaCamera2View initialization. opencv#24869

Added automatic image rotation to JavaCamera2View and NativeCameraView so the video preview was matched with screen orientation.
Fixed double preview initialization bug in JavaCamera2View.
Added proper cameraID parsing to NativeCameraView similar to JavaCameraView

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants