![](/img/trans.png)
[英]Using the Android gyroscope in Unity3d, how can I set the initial camera rotation to the initial mobile device rotation?
[英]Android opencv camera rotation issue in mobile device
我已經為800 * 480屏幕分辨率的特定平板設備開發了一個android應用程序。 該項目的目標是捕獲圖像(使用面部檢測)。 為此,我使用opencv2.4.2 sdk捕獲圖像(使用opencv人臉檢測示例)。 在該設備中,相機位於右下角。 因此,我使用反向人像模式(使用轉置圖像)捕獲了圖像。
The code snippet is below:
@Override
protected Bitmap processFrame(VideoCapture capture) {
FdActivity.mSquaredImage = 0;
resolution = 0;
capture.retrieve(mRgba, Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA);
capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
Core.transpose(mRgba, mRgba);
Core.transpose(mRgba, mGray);
.....
.....
return bmp;
}
在android平板電腦中工作正常。
現在,我想在移動設備上使用我的應用程序。 所以我用三星GALAXY S II進行了測試。
我有一個問題。
The following code is to open the camera.
The code snippet is below:
public boolean openCamera() {
Log.i(TAG, "openCamera");
synchronized (this) {
releaseCamera();
mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID);
if (!mCamera.isOpened()) {
mCamera.release();
mCamera = null;
Log.e(TAG, "Failed to open native camera");
return false;
}
}
return true;
}
此代碼在平板電腦中打開前置攝像頭。 但是在三星GALAXY S II中,它打開了后置攝像頭。 為此,我在opencv.org論壇中搜索了以下解決方案,
mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID+1);
現在,它將在SAMSUNG GALAXY S II中打開前置攝像頭。 但是在平板電腦中,我收到“無法打開相機”錯誤。 可能是什么問題。 我用HTC渴望android設備進行了測試。 但是它僅顯示空白屏幕(相機未打開)。
新的要求是用戶將攝像機的位置保持在設備頂部。 如果他們旋轉設備,屏幕和圖像不應旋轉 。
非常緊急。 請有人可以幫我解決這個問題嗎?
Android設備可以具有多個攝像頭(正面或背面)。 解決這種情況的最佳方法是先檢查攝像機的數量和面對的方式,而不要使用固定的攝像機ID。 例如,如果您正在尋找前置攝像頭,則可以使用以下方法:
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
int cameraCount = Camera.getNumberOfCameras();
for (int camIdx = 0; camIdx < cameraCount; camIdx++)
{
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT)
{
mCamera = new VideoCapture(Highgui.CV_CAP_ANDROID+camIdx);
break;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.