我嘗試在Android預覽的當前幀上執行一些ImageProcessing。 在其他智能手機的情況下,它的工作非常好。但現在,我必須讓Nexus 5x可以訪問應用程序。預覽中的Nexus 5x幀已打開Camera2
在那裏,我從預覽中獲得180度轉動的圖像。我該如何解決這個問題? 這裏我設置了我的相機和預覽代碼:
private void resetCamera(int width, int height){
Log.d(TAG, "Reset Camera!");
CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
for (String cameraId : cameraManager.getCameraIdList()) {
CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
mSensorOrientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
continue;
}
StreamConfigurationMap map = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
mImageReader = ImageReader.newInstance(width,
height,
ImageFormat.YUV_420_888,
10);
mImageReader.setOnImageAvailableListener(mOnImageAvailableTrack,
mBackgroundHandler);
mPreviewSize = getPreferredPreviewSize(map.getOutputSizes(SurfaceTexture.class), width, height);
mCameraId = cameraId;
return;
}
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
前瞻:
private void createTrackingPreviewSession(){
try{
SurfaceTexture surfaceTexture = mTextureView.getSurfaceTexture();
surfaceTexture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
Surface previewSurface = new Surface(surfaceTexture);
mPreviewCaptureBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mPreviewCaptureBuilder.addTarget(previewSurface);
mPreviewCaptureBuilder.addTarget(mImageReader.getSurface());
int rotation = getWindowManager().getDefaultDisplay().getRotation();
mPreviewCaptureBuilder.set(CaptureRequest.JPEG_ORIENTATION,
getOrientation(rotation));
mCameraDevice.createCaptureSession(Arrays.asList(previewSurface, mImageReader.getSurface()),
new CameraCaptureSession.StateCallback(){
@Override
public void onConfigured(CameraCaptureSession session) {
if(mCameraDevice == null){
return;
}
try{
Toast.makeText(getApplicationContext(), "Create Tracking Session", Toast.LENGTH_SHORT).show();
mPreviewCapture = mPreviewCaptureBuilder.build();
mCaptureSession = session;
mCaptureSession.setRepeatingRequest(
mPreviewCapture,
mSessionCaptureCallback,
mBackgroundHandler
);
} catch(CameraAccessException e){
e.printStackTrace();
}
}
@Override
public void onConfigureFailed(CameraCaptureSession session) {
Toast.makeText(
getApplicationContext(),
"create Camera session failed!",
Toast.LENGTH_SHORT
).show();
}
}, null);
} catch(CameraAccessException e){
e.printStackTrace();
}
}
正如你所看到的,我試圖用修復用於捕捉圖像,但它並沒有幫助我仍然從預覽中獲得一個轉動的圖像。
如果可能,我想要一個解決方案,它試圖改變相機的設置。我不想在通過綁定的ImageReader獲取它之後自行關閉圖像。
沒有預覽是正常的,沒關係。但是當我拍攝「照片」(通過ImageReader獲取當前幀)時,它會旋轉90度。我已經使用配置轉換方法正確顯示預覽。 –
您是否打電話 captureBuilder.set(CaptureRequest.JPEG_ORIENTATION,getOrientation(rotation)); – greenteafox
隨着正確的旋轉?某些相機設備旋轉角度爲90°,就像您的Nexus手機一樣,另外一些則爲270。 – greenteafox