大家早上好。我正在开发一个 Android 应用程序。我在 logcat 中收到此异常:
06-16 11:42:41.726: WARN/dalvikvm(11429): threadid=13: thread exiting with uncaught exception (group=0x40e61ac8)
06-16 11:42:41.726: ERROR/AndroidRuntime(11429): FATAL EXCEPTION: Thread-2473
CvException [org.opencv.core.CvException: /home/reports/ci/slave/50-SDK/opencv/modules/imgproc/src/imgwarp.cpp:3272: error: (-215) src.cols > 0 && src.rows > 0 in function void cv::warpAffine(cv::InputArray, cv::OutputArray, cv::InputArray, cv::Size, int, int, const Scalar&)
]
at org.opencv.imgproc.Imgproc.warpAffine_2(Native Method)
at org.opencv.imgproc.Imgproc.warpAffine(Imgproc.java:9114)
at com.micaela.myapp.MainActivity.manageRotation(MainActivity.java:416)
at com.micaela.myapp.MainActivity.chooseMode(MainActivity.java:374)
at com.micaela.myapp.MainActivity.onCameraFrame(MainActivity.java:344)
at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:381)
at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:323)
at java.lang.Thread.run(Thread.java:856)
我的应用程序使用对象 JavaCameraView 打开一个视频流,并从中捕获帧,然后在屏幕上显示它们之前,它们会根据设备的方向正确旋转。为此,我在 2.4.5 版本中使用了 OpenCv4Android 库的 warpAffine 函数。
我调用这个函数的方法是:
public void manageRotation(Mat matrix, Display display) {
int screenOrientation = display.getRotation();
Point center =new Point(matrix.cols()/2,matrix.rows()/2);
int angle = 0; //default
double scale = 1.0;
Mat rotImage;
switch (screenOrientation){
default:
case ORIENTATION_0: // Portrait
if (mOpenCvCameraView.getCameraId() == Camera.CameraInfo.CAMERA_FACING_FRONT) {
angle=90;
rotImage = Imgproc.getRotationMatrix2D(center, angle, scale);
Imgproc.warpAffine(matrix, matrix, rotImage, matrix.size());
} else{
angle=-90;
rotImage = Imgproc.getRotationMatrix2D(center, angle, scale);
Imgproc.warpAffine(matrix, matrix, rotImage, matrix.size());
}
break;
case ORIENTATION_90: // Landscape right
angle = 180;
rotImage = Imgproc.getRotationMatrix2D(center, angle, scale);
Imgproc.warpAffine(matrix, matrix, rotImage, matrix.size());
break;
case ORIENTATION_180: //Reverse portrait
angle = 270;
rotImage = Imgproc.getRotationMatrix2D(center, angle, scale);
Imgproc.warpAffine(matrix, matrix, rotImage, matrix.size());
break;
case ORIENTATION_270: // Landscape left
break;
}
}
在捕获帧后,我在 OnCameraFrame 中调用此方法,并将其作为参数传递。我该如何解决这个问题?