mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge branch 4.x
This commit is contained in:
@@ -99,7 +99,7 @@ gradle.afterProject { project ->
|
||||
// Android Gradle Plugin (AGP) 3.5+ is required
|
||||
// https://github.com/android/ndk-samples/wiki/Configure-NDK-Path
|
||||
def isNdkVersionSupported = project.android.metaClass.getProperties().find { it.name == 'ndkVersion' } != null
|
||||
if ((false || opencv_strict_build_configuration) && isNdkVersionSupported) {
|
||||
if (opencv_strict_build_configuration && isNdkVersionSupported) {
|
||||
gradle.println("Override ndkVersion for the project ${project.name}")
|
||||
project.android {
|
||||
ndkVersion '@ANDROID_NDK_REVISION@'
|
||||
|
||||
@@ -14,10 +14,11 @@ android {
|
||||
cmake {
|
||||
if (gradle.opencv_source == "sdk_path") {
|
||||
arguments "-DOpenCV_DIR=" + project(':opencv').projectDir + "/@ANDROID_PROJECT_JNI_PATH@",
|
||||
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
|
||||
"-DOPENCV_FROM_SDK=TRUE"@OPENCV_ANDROID_CMAKE_EXTRA_ARGS@
|
||||
|
||||
} else {
|
||||
arguments "-DOPENCV_VERSION_MAJOR=@OPENCV_VERSION_MAJOR@",
|
||||
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
|
||||
"-DOPENCV_FROM_SDK=FALSE"@OPENCV_ANDROID_CMAKE_EXTRA_ARGS@
|
||||
}
|
||||
targets "mixed_sample"
|
||||
|
||||
@@ -14,6 +14,14 @@ endif()
|
||||
message(STATUS "ANDROID_ABI=${ANDROID_ABI}")
|
||||
find_package(OpenCV REQUIRED COMPONENTS ${ANDROID_OPENCV_COMPONENTS})
|
||||
|
||||
# For 16k pages support with NDK prior 27
|
||||
# Details: https://developer.android.com/guide/practices/page-sizes?hl=en
|
||||
if(ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES)
|
||||
if(ANDROID_ABI STREQUAL arm64-v8a OR ANDROID_ABI STREQUAL x86_64)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=16384")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
file(GLOB srcs *.cpp *.c)
|
||||
file(GLOB hdrs *.hpp *.h)
|
||||
|
||||
|
||||
@@ -15,11 +15,13 @@ android {
|
||||
if (gradle.opencv_source == "sdk_path") {
|
||||
arguments "-DOpenCV_DIR=" + project(':opencv').projectDir + "/@ANDROID_PROJECT_JNI_PATH@",
|
||||
"-DOPENCV_FROM_SDK=TRUE",
|
||||
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
|
||||
"-DANDROID_OPENCL_SDK=@ANDROID_OPENCL_SDK@" @OPENCV_ANDROID_CMAKE_EXTRA_ARGS@
|
||||
|
||||
} else {
|
||||
arguments "-DOPENCV_VERSION_MAJOR=@OPENCV_VERSION_MAJOR@",
|
||||
"-DOPENCV_FROM_SDK=FALSE",
|
||||
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
|
||||
"-DANDROID_OPENCL_SDK=@ANDROID_OPENCL_SDK@" @OPENCV_ANDROID_CMAKE_EXTRA_ARGS@
|
||||
}
|
||||
targets "JNIpart"
|
||||
|
||||
@@ -18,6 +18,14 @@ find_package(OpenCL QUIET)
|
||||
file(GLOB srcs *.cpp *.c)
|
||||
file(GLOB hdrs *.hpp *.h)
|
||||
|
||||
# For 16k pages support with NDK prior 27
|
||||
# Details: https://developer.android.com/guide/practices/page-sizes?hl=en
|
||||
if(ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES)
|
||||
if(ANDROID_ABI STREQUAL arm64-v8a OR ANDROID_ABI STREQUAL x86_64)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=16384")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include_directories("${CMAKE_CURRENT_LIST_DIR}")
|
||||
add_library(${target} SHARED ${srcs} ${hdrs})
|
||||
|
||||
|
||||
+16
-13
@@ -57,7 +57,6 @@ public class RecorderActivity extends CameraActivity implements CvCameraViewList
|
||||
private VideoWriter mVideoWriter = null;
|
||||
private VideoCapture mVideoCapture = null;
|
||||
private Mat mVideoFrame;
|
||||
private Mat mRenderFrame;
|
||||
|
||||
public RecorderActivity() {
|
||||
Log.i(TAG, "Instantiated new " + this.getClass());
|
||||
@@ -122,7 +121,6 @@ public class RecorderActivity extends CameraActivity implements CvCameraViewList
|
||||
mTriggerButton.setText("Start Camera");
|
||||
|
||||
mVideoFrame.release();
|
||||
mRenderFrame.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -132,7 +130,6 @@ public class RecorderActivity extends CameraActivity implements CvCameraViewList
|
||||
super.onResume();
|
||||
|
||||
mVideoFrame = new Mat();
|
||||
mRenderFrame = new Mat();
|
||||
|
||||
changeStatus();
|
||||
}
|
||||
@@ -167,16 +164,15 @@ public class RecorderActivity extends CameraActivity implements CvCameraViewList
|
||||
{
|
||||
Log.d(TAG, "Camera frame arrived");
|
||||
|
||||
Mat rgbMat = inputFrame.rgba();
|
||||
mVideoFrame = inputFrame.rgba();
|
||||
|
||||
Log.d(TAG, "Size: " + rgbMat.width() + "x" + rgbMat.height());
|
||||
Log.d(TAG, "Size: " + mVideoFrame.width() + "x" + mVideoFrame.height());
|
||||
|
||||
if (mVideoWriter != null && mVideoWriter.isOpened()) {
|
||||
Imgproc.cvtColor(rgbMat, mVideoFrame, Imgproc.COLOR_RGBA2BGR);
|
||||
mVideoWriter.write(mVideoFrame);
|
||||
}
|
||||
|
||||
return rgbMat;
|
||||
return mVideoFrame;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -294,12 +290,16 @@ public class RecorderActivity extends CameraActivity implements CvCameraViewList
|
||||
mVideoCapture = new VideoCapture(mVideoFilename, Videoio.CAP_OPENCV_MJPEG);
|
||||
}
|
||||
|
||||
if (!mVideoCapture.isOpened()) {
|
||||
if (mVideoCapture == null || !mVideoCapture.isOpened()) {
|
||||
Log.e(TAG, "Can't open video");
|
||||
Toast.makeText(this, "Can't open file " + mVideoFilename, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mUseBuiltInMJPG){
|
||||
mVideoCapture.set(Videoio.CAP_PROP_FOURCC, VideoWriter.fourcc('R','G','B','4'));
|
||||
}
|
||||
|
||||
Toast.makeText(this, "Starting playback from file " + mVideoFilename, Toast.LENGTH_SHORT).show();
|
||||
|
||||
mPlayerThread = new Runnable() {
|
||||
@@ -315,11 +315,14 @@ public class RecorderActivity extends CameraActivity implements CvCameraViewList
|
||||
}
|
||||
return;
|
||||
}
|
||||
// VideoCapture with CAP_ANDROID generates RGB frames instead of BGR
|
||||
// https://github.com/opencv/opencv/issues/24687
|
||||
Imgproc.cvtColor(mVideoFrame, mRenderFrame, mUseBuiltInMJPG ? Imgproc.COLOR_BGR2RGBA: Imgproc.COLOR_RGB2RGBA);
|
||||
Bitmap bmp = Bitmap.createBitmap(mRenderFrame.cols(), mRenderFrame.rows(), Bitmap.Config.ARGB_8888);
|
||||
Utils.matToBitmap(mRenderFrame, bmp);
|
||||
|
||||
// MJPEG codec will output BGR only. So we need to convert to RGBA.
|
||||
if (mUseBuiltInMJPG) {
|
||||
Imgproc.cvtColor(mVideoFrame, mVideoFrame, Imgproc.COLOR_BGR2RGBA);
|
||||
}
|
||||
|
||||
Bitmap bmp = Bitmap.createBitmap(mVideoFrame.cols(), mVideoFrame.rows(), Bitmap.Config.ARGB_8888);
|
||||
Utils.matToBitmap(mVideoFrame, bmp);
|
||||
mImageView.setImageBitmap(bmp);
|
||||
Handler h = new Handler();
|
||||
h.postDelayed(this, 33);
|
||||
|
||||
Reference in New Issue
Block a user