From f379bcc6d325d20ccb3589a8091d0d5649c41eb3 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Wed, 1 Oct 2014 11:44:28 +0400 Subject: [PATCH 1/7] Suppressed some iOS framework compilation warnings --- platforms/ios/build_framework.py | 40 ++++++++++++++----- .../ios/cmake/Modules/Platform/iOS.cmake | 10 ++++- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/platforms/ios/build_framework.py b/platforms/ios/build_framework.py index e28dc6d880..28ce885b20 100755 --- a/platforms/ios/build_framework.py +++ b/platforms/ios/build_framework.py @@ -25,7 +25,18 @@ The script should handle minor OpenCV updates efficiently However, opencv2.framework directory is erased and recreated on each run. """ -import glob, re, os, os.path, shutil, string, sys +import glob, re, os, os.path, shutil, string, sys, exceptions, subprocess + +def execute(cmd): + try: + print >>sys.stderr, "Executing:", cmd + retcode = subprocess.call(cmd, shell=True) + if retcode < 0: + raise Exception("Child was terminated by signal:", -retcode) + elif retcode > 0: + raise Exception("Child returned:", retcode) + except OSError as e: + raise Exception("Execution failed:", e) def build_opencv(srcroot, buildroot, target, arch): "builds OpenCV for device or simulator" @@ -48,17 +59,17 @@ def build_opencv(srcroot, buildroot, target, arch): # if cmake cache exists, just rerun cmake to update OpenCV.xcodeproj if necessary if os.path.isfile(os.path.join(builddir, "CMakeCache.txt")): - os.system("cmake %s ." % (cmakeargs,)) + execute("cmake %s ." % (cmakeargs,)) else: - os.system("cmake %s %s" % (cmakeargs, srcroot)) + execute("cmake %s %s" % (cmakeargs, srcroot)) for wlib in [builddir + "/modules/world/UninstalledProducts/libopencv_world.a", builddir + "/lib/Release/libopencv_world.a"]: if os.path.isfile(wlib): os.remove(wlib) - os.system("xcodebuild IPHONEOS_DEPLOYMENT_TARGET=6.0 -parallelizeTargets ARCHS=%s -jobs 8 -sdk %s -configuration Release -target ALL_BUILD" % (arch, target.lower())) - os.system("xcodebuild IPHONEOS_DEPLOYMENT_TARGET=6.0 ARCHS=%s -sdk %s -configuration Release -target install install" % (arch, target.lower())) + execute("xcodebuild IPHONEOS_DEPLOYMENT_TARGET=6.0 -parallelizeTargets ARCHS=%s -jobs 8 -sdk %s -configuration Release -target ALL_BUILD" % (arch, target.lower())) + execute("xcodebuild IPHONEOS_DEPLOYMENT_TARGET=6.0 ARCHS=%s -sdk %s -configuration Release -target install install" % (arch, target.lower())) os.chdir(currdir) def put_framework_together(srcroot, dstroot): @@ -86,7 +97,7 @@ def put_framework_together(srcroot, dstroot): # make universal static lib wlist = " ".join(["../build/" + t + "/lib/Release/libopencv_world.a" for t in targetlist]) - os.system("lipo -create " + wlist + " -o " + dstdir + "/opencv2") + execute("lipo -create " + wlist + " -o " + dstdir + "/opencv2") # copy Info.plist shutil.copyfile(tdir0 + "/ios/Info.plist", dstdir + "/Resources/Info.plist") @@ -101,10 +112,13 @@ def put_framework_together(srcroot, dstroot): def build_framework(srcroot, dstroot): "main function to do all the work" - targets = ["iPhoneOS", "iPhoneOS", "iPhoneOS", "iPhoneSimulator", "iPhoneSimulator"] - archs = ["armv7", "armv7s", "arm64", "i386", "x86_64"] - for i in range(len(targets)): - build_opencv(srcroot, os.path.join(dstroot, "build"), targets[i], archs[i]) + targets = [("armv7", "iPhoneOS"), + ("armv7s", "iPhoneOS"), + ("arm64", "iPhoneOS"), + ("i386", "iPhoneSimulator"), + ("x86_64", "iPhoneSimulator")] + for t in targets: + build_opencv(srcroot, os.path.join(dstroot, "build"), t[1], t[0]) put_framework_together(srcroot, dstroot) @@ -114,4 +128,8 @@ if __name__ == "__main__": print "Usage:\n\t./build_framework.py \n\n" sys.exit(0) - build_framework(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "../..")), os.path.abspath(sys.argv[1])) + try: + build_framework(os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "../..")), os.path.abspath(sys.argv[1])) + except Exception as e: + print >>sys.stderr, e + sys.exit(1) diff --git a/platforms/ios/cmake/Modules/Platform/iOS.cmake b/platforms/ios/cmake/Modules/Platform/iOS.cmake index e021aca55f..a1ecdeaf3c 100644 --- a/platforms/ios/cmake/Modules/Platform/iOS.cmake +++ b/platforms/ios/cmake/Modules/Platform/iOS.cmake @@ -40,10 +40,16 @@ set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") # Hidden visibilty is required for cxx on iOS set (CMAKE_C_FLAGS "") -set (CMAKE_CXX_FLAGS "-stdlib=libc++ -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden") - +set (CMAKE_CXX_FLAGS "-stdlib=libc++ -fvisibility=hidden -fvisibility-inlines-hidden") set (CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3 -fomit-frame-pointer -ffast-math") +# Silence some warnings +set (no_warn "-Wno-unused-function -Wno-unused-parameter -Wno-strict-prototypes -Wno-missing-prototypes -Wno-missing-declarations -Wno-unused-const-variable -Wno-overloaded-virtual") +set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${no_warn}") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${no_warn}") +# Additional linker flag +set (CMAKE_CXX_LINK_FLAGS "-Wl,-headerpad_max_install_names ${CMAKE_CXX_LINK_FLAGS}") + if (HAVE_FLAG_SEARCH_PATHS_FIRST) set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}") From 630eddf25a858e7eae03fd308cc8a3a93dfe58e9 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 17 Oct 2014 14:37:25 +0400 Subject: [PATCH 2/7] Extracted repeated cmake instruction block --- cmake/OpenCVUtils.cmake | 18 ++++++++++++++++++ modules/highgui/CMakeLists.txt | 16 +--------------- modules/imgcodecs/CMakeLists.txt | 16 +--------------- modules/videoio/CMakeLists.txt | 16 +--------------- 4 files changed, 21 insertions(+), 45 deletions(-) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 96321f9294..b32465ead2 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -242,6 +242,24 @@ macro(ocv_warnings_disable) endif(NOT ENABLE_NOISY_WARNINGS) endmacro() +macro(add_apple_compiler_options the_module) + ocv_check_flag_support(OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS) + if(HAVE_OBJC_EXCEPTIONS) + foreach(source ${OPENCV_MODULE_${the_module}_SOURCES}) + if("${source}" MATCHES "\\.mm$") + get_source_file_property(flags "${source}" COMPILE_FLAGS) + if(flags) + set(flags "${_flags} -fobjc-exceptions") + else() + set(flags "-fobjc-exceptions") + endif() + + set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}") + endif() + endforeach() + endif() +endmacro() + # Provides an option that the user can optionally select. # Can accept condition to control when option is available for user. # Usage: diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index de8c27ba33..174a620020 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -98,21 +98,7 @@ ocv_create_module(${HIGHGUI_LIBRARIES}) macro(ocv_highgui_configure_target) if(APPLE) - ocv_check_flag_support(OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS) - if(HAVE_OBJC_EXCEPTIONS) - foreach(source ${OPENCV_MODULE_${the_module}_SOURCES}) - if("${source}" MATCHES "\\.mm$") - get_source_file_property(flags "${source}" COMPILE_FLAGS) - if(flags) - set(flags "${_flags} -fobjc-exceptions") - else() - set(flags "-fobjc-exceptions") - endif() - - set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}") - endif() - endforeach() - endif() + add_apple_compiler_options(the_module) endif() if(BUILD_SHARED_LIBS) diff --git a/modules/imgcodecs/CMakeLists.txt b/modules/imgcodecs/CMakeLists.txt index 67054053cd..3d0110ef48 100644 --- a/modules/imgcodecs/CMakeLists.txt +++ b/modules/imgcodecs/CMakeLists.txt @@ -106,21 +106,7 @@ ocv_create_module(${GRFMT_LIBS} ${IMGCODECS_LIBRARIES}) macro(ocv_imgcodecs_configure_target) if(APPLE) - ocv_check_flag_support(OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS) - if(HAVE_OBJC_EXCEPTIONS) - foreach(source ${OPENCV_MODULE_${the_module}_SOURCES}) - if("${source}" MATCHES "\\.mm$") - get_source_file_property(flags "${source}" COMPILE_FLAGS) - if(flags) - set(flags "${_flags} -fobjc-exceptions") - else() - set(flags "-fobjc-exceptions") - endif() - - set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}") - endif() - endforeach() - endif() + add_apple_compiler_options(the_module) endif() if(BUILD_SHARED_LIBS) diff --git a/modules/videoio/CMakeLists.txt b/modules/videoio/CMakeLists.txt index 7c8f6a058f..1635e2022f 100644 --- a/modules/videoio/CMakeLists.txt +++ b/modules/videoio/CMakeLists.txt @@ -189,21 +189,7 @@ ocv_create_module(${VIDEOIO_LIBRARIES}) macro(ocv_videoio_configure_target) if(APPLE) - ocv_check_flag_support(OBJCXX "-fobjc-exceptions" HAVE_OBJC_EXCEPTIONS) - if(HAVE_OBJC_EXCEPTIONS) - foreach(source ${OPENCV_MODULE_${the_module}_SOURCES}) - if("${source}" MATCHES "\\.mm$") - get_source_file_property(flags "${source}" COMPILE_FLAGS) - if(flags) - set(flags "${_flags} -fobjc-exceptions") - else() - set(flags "-fobjc-exceptions") - endif() - - set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}") - endif() - endforeach() - endif() + add_apple_compiler_options(the_module) endif() if(BUILD_SHARED_LIBS) From 420737e09891b1b176638864ea4000dd033d0d11 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 17 Oct 2014 15:45:13 +0400 Subject: [PATCH 3/7] Fixing iOS clang warnings, part 1 --- modules/imgcodecs/src/ios_conversions.mm | 3 +++ modules/imgproc/src/demosaicing.cpp | 3 ++- modules/imgproc/src/pyramids.cpp | 15 +++++++++++---- modules/videoio/src/cap_avfoundation.mm | 13 +++++++------ modules/videoio/src/cap_ios_abstract_camera.mm | 4 ++-- modules/videoio/src/cap_ios_video_camera.mm | 5 +++-- platforms/ios/cmake/Modules/Platform/iOS.cmake | 2 +- 7 files changed, 29 insertions(+), 16 deletions(-) diff --git a/modules/imgcodecs/src/ios_conversions.mm b/modules/imgcodecs/src/ios_conversions.mm index af522900c8..c191ffeaec 100644 --- a/modules/imgcodecs/src/ios_conversions.mm +++ b/modules/imgcodecs/src/ios_conversions.mm @@ -47,6 +47,9 @@ #include "opencv2/core.hpp" #include "precomp.hpp" +UIImage* MatToUIImage(const cv::Mat& image); +void UIImageToMat(const UIImage* image, cv::Mat& m, bool alphaExist); + UIImage* MatToUIImage(const cv::Mat& image) { NSData *data = [NSData dataWithBytes:image.data diff --git a/modules/imgproc/src/demosaicing.cpp b/modules/imgproc/src/demosaicing.cpp index 01a84ee8ed..e894710cd0 100644 --- a/modules/imgproc/src/demosaicing.cpp +++ b/modules/imgproc/src/demosaicing.cpp @@ -368,7 +368,8 @@ public: uint16x8_t g0 = vaddq_u16(vshrq_n_u16(r0, 8), vshrq_n_u16(r2, 8)); uint16x8_t g1 = vandq_u16(r1, masklo); g0 = vaddq_u16(g0, vaddq_u16(g1, vextq_u16(g1, g1, 1))); - g1 = vshlq_n_u16(vextq_u16(g1, g1, 1), 2); + uint16x8_t rot = vextq_u16(g1, g1, 1) + g1 = vshlq_n_u16(rot, 2); // g0 = b0 b2 b4 ... // g1 = b1 b3 b5 ... diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index c54dfd3aea..15ff1ac345 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -240,14 +240,18 @@ struct PyrDownVec_32s16u int32x4_t v_r20 = vld1q_s32(row2 + x), v_r21 = vld1q_s32(row2 + x + 4); int32x4_t v_r30 = vld1q_s32(row3 + x), v_r31 = vld1q_s32(row3 + x + 4); int32x4_t v_r40 = vld1q_s32(row4 + x), v_r41 = vld1q_s32(row4 + x + 4); + int32x4_t shifted; v_r00 = vaddq_s32(vqaddq_s32(v_r00, v_r40), vqaddq_s32(v_r20, v_r20)); v_r10 = vaddq_s32(vqaddq_s32(v_r10, v_r20), v_r30); - int32x4_t v_dst0 = vshrq_n_s32(vaddq_s32(vqaddq_s32(v_r00, vshlq_n_s32(v_r10, 2)), v_delta), 8); + + shifted = vshlq_n_s32(v_r10, 2); + int32x4_t v_dst0 = vshrq_n_s32(vaddq_s32(vqaddq_s32(v_r00, shifted), v_delta), 8); v_r01 = vaddq_s32(vqaddq_s32(v_r01, v_r41), vqaddq_s32(v_r21, v_r21)); v_r11 = vaddq_s32(vqaddq_s32(v_r11, v_r21), v_r31); - int32x4_t v_dst1 = vshrq_n_s32(vaddq_s32(vqaddq_s32(v_r01, vshlq_n_s32(v_r11, 2)), v_delta), 8); + shifted = vshlq_n_s32(v_r11, 2) + int32x4_t v_dst1 = vshrq_n_s32(vaddq_s32(vqaddq_s32(v_r01, shifted), v_delta), 8); vst1q_u16(dst + x, vcombine_u16(vqmovun_s32(v_dst0), vqmovun_s32(v_dst1))); } @@ -271,14 +275,17 @@ struct PyrDownVec_32s16s int32x4_t v_r20 = vld1q_s32(row2 + x), v_r21 = vld1q_s32(row2 + x + 4); int32x4_t v_r30 = vld1q_s32(row3 + x), v_r31 = vld1q_s32(row3 + x + 4); int32x4_t v_r40 = vld1q_s32(row4 + x), v_r41 = vld1q_s32(row4 + x + 4); + int32x4_t shifted; v_r00 = vaddq_s32(vqaddq_s32(v_r00, v_r40), vqaddq_s32(v_r20, v_r20)); v_r10 = vaddq_s32(vqaddq_s32(v_r10, v_r20), v_r30); - int32x4_t v_dst0 = vshrq_n_s32(vaddq_s32(vqaddq_s32(v_r00, vshlq_n_s32(v_r10, 2)), v_delta), 8); + shifted = vshlq_n_s32(v_r10, 2); + int32x4_t v_dst0 = vshrq_n_s32(vaddq_s32(vqaddq_s32(v_r00, shifted), v_delta), 8); v_r01 = vaddq_s32(vqaddq_s32(v_r01, v_r41), vqaddq_s32(v_r21, v_r21)); v_r11 = vaddq_s32(vqaddq_s32(v_r11, v_r21), v_r31); - int32x4_t v_dst1 = vshrq_n_s32(vaddq_s32(vqaddq_s32(v_r01, vshlq_n_s32(v_r11, 2)), v_delta), 8); + shifted = vshlq_n_s32(v_r11, 2); + int32x4_t v_dst1 = vshrq_n_s32(vaddq_s32(vqaddq_s32(v_r01, shifted), v_delta), 8); vst1q_s16(dst + x, vcombine_s16(vqmovn_s32(v_dst0), vqmovn_s32(v_dst1))); } diff --git a/modules/videoio/src/cap_avfoundation.mm b/modules/videoio/src/cap_avfoundation.mm index e66f03a8da..f52700d3b0 100644 --- a/modules/videoio/src/cap_avfoundation.mm +++ b/modules/videoio/src/cap_avfoundation.mm @@ -181,7 +181,6 @@ class CvVideoWriter_AVFoundation : public CvVideoWriter{ AVAssetWriterInput* mMovieWriterInput; AVAssetWriterInputPixelBufferAdaptor* mMovieWriterAdaptor; - unsigned char* imagedata; NSString* path; NSString* codec; NSString* fileType; @@ -490,15 +489,15 @@ double CvCaptureCAM::getProperty(int property_id){ CMFormatDescriptionRef format = [[ports objectAtIndex:0] formatDescription]; CGSize s1 = CMVideoFormatDescriptionGetPresentationDimensions(format, YES, YES); - int width=(int)s1.width, height=(int)s1.height; + int w=(int)s1.width, h=(int)s1.height; [localpool drain]; switch (property_id) { case CV_CAP_PROP_FRAME_WIDTH: - return width; + return w; case CV_CAP_PROP_FRAME_HEIGHT: - return height; + return h; case CV_CAP_PROP_IOS_DEVICE_FOCUS: return mCaptureDevice.focusMode; @@ -659,6 +658,8 @@ fromConnection:(AVCaptureConnection *)connection{ // Failed // connection.videoOrientation = AVCaptureVideoOrientationPortrait; + (void)captureOutput; + (void)connection; CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); @@ -1009,7 +1010,7 @@ double CvCaptureFile::getFPS() { return 30.0; //TODO: Debugging } -double CvCaptureFile::getProperty(int property_id){ +double CvCaptureFile::getProperty(int /*property_id*/){ /* if (mCaptureSession == nil) return 0; @@ -1050,7 +1051,7 @@ double CvCaptureFile::getProperty(int property_id){ return 1.0; //Debugging } -bool CvCaptureFile::setProperty(int property_id, double value) { +bool CvCaptureFile::setProperty(int /*property_id*/, double /*value*/) { /* if (mCaptureSession == nil) return false; diff --git a/modules/videoio/src/cap_ios_abstract_camera.mm b/modules/videoio/src/cap_ios_abstract_camera.mm index 08547663ca..6af40459ad 100644 --- a/modules/videoio/src/cap_ios_abstract_camera.mm +++ b/modules/videoio/src/cap_ios_abstract_camera.mm @@ -308,7 +308,7 @@ if ([device position] == desiredPosition) { [self.captureSession beginConfiguration]; - NSError* error; + NSError* error = nil; AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; if (!input) { NSLog(@"error creating input %@", [error localizedDescription]); @@ -316,7 +316,7 @@ // support for autofocus if ([device isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]) { - NSError *error = nil; + error = nil; if ([device lockForConfiguration:&error]) { device.focusMode = AVCaptureFocusModeContinuousAutoFocus; [device unlockForConfiguration]; diff --git a/modules/videoio/src/cap_ios_video_camera.mm b/modules/videoio/src/cap_ios_video_camera.mm index c094de79c1..4d05f673ae 100644 --- a/modules/videoio/src/cap_ios_video_camera.mm +++ b/modules/videoio/src/cap_ios_video_camera.mm @@ -101,7 +101,7 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;} [super start]; if (self.recordVideo == YES) { - NSError* error; + NSError* error = nil; if ([[NSFileManager defaultManager] fileExistsAtPath:[self videoFileString]]) { [[NSFileManager defaultManager] removeItemAtPath:[self videoFileString] error:&error]; } @@ -424,6 +424,8 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;} - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { + (void)captureOutput; + (void)connection; if (self.delegate) { // convert from Core Media to Core Video @@ -464,7 +466,6 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;} // delegate image processing to the delegate cv::Mat image(height, width, format_opencv, bufferAddress, bytesPerRow); - cv::Mat* result = NULL; CGImage* dstImage; if ([self.delegate respondsToSelector:@selector(processImage:)]) { diff --git a/platforms/ios/cmake/Modules/Platform/iOS.cmake b/platforms/ios/cmake/Modules/Platform/iOS.cmake index a1ecdeaf3c..0db95fb17b 100644 --- a/platforms/ios/cmake/Modules/Platform/iOS.cmake +++ b/platforms/ios/cmake/Modules/Platform/iOS.cmake @@ -44,7 +44,7 @@ set (CMAKE_CXX_FLAGS "-stdlib=libc++ -fvisibility=hidden -fvisibility-inlines-hi set (CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3 -fomit-frame-pointer -ffast-math") # Silence some warnings -set (no_warn "-Wno-unused-function -Wno-unused-parameter -Wno-strict-prototypes -Wno-missing-prototypes -Wno-missing-declarations -Wno-unused-const-variable -Wno-overloaded-virtual") +set (no_warn "-Wno-semicolon-before-method-body -Wno-unused-function -Wno-unused-parameter -Wno-strict-prototypes -Wno-missing-prototypes -Wno-missing-declarations -Wno-unused-const-variable -Wno-overloaded-virtual") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${no_warn}") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${no_warn}") # Additional linker flag From d3821e8cd73bcfd4f44abd02f7cf67b696df3319 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 17 Oct 2014 15:50:57 +0400 Subject: [PATCH 4/7] Forgotten punctuation --- modules/imgproc/src/demosaicing.cpp | 2 +- modules/imgproc/src/pyramids.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/imgproc/src/demosaicing.cpp b/modules/imgproc/src/demosaicing.cpp index e894710cd0..0b7afb8ea6 100644 --- a/modules/imgproc/src/demosaicing.cpp +++ b/modules/imgproc/src/demosaicing.cpp @@ -368,7 +368,7 @@ public: uint16x8_t g0 = vaddq_u16(vshrq_n_u16(r0, 8), vshrq_n_u16(r2, 8)); uint16x8_t g1 = vandq_u16(r1, masklo); g0 = vaddq_u16(g0, vaddq_u16(g1, vextq_u16(g1, g1, 1))); - uint16x8_t rot = vextq_u16(g1, g1, 1) + uint16x8_t rot = vextq_u16(g1, g1, 1); g1 = vshlq_n_u16(rot, 2); // g0 = b0 b2 b4 ... // g1 = b1 b3 b5 ... diff --git a/modules/imgproc/src/pyramids.cpp b/modules/imgproc/src/pyramids.cpp index 15ff1ac345..164ae50161 100644 --- a/modules/imgproc/src/pyramids.cpp +++ b/modules/imgproc/src/pyramids.cpp @@ -250,7 +250,7 @@ struct PyrDownVec_32s16u v_r01 = vaddq_s32(vqaddq_s32(v_r01, v_r41), vqaddq_s32(v_r21, v_r21)); v_r11 = vaddq_s32(vqaddq_s32(v_r11, v_r21), v_r31); - shifted = vshlq_n_s32(v_r11, 2) + shifted = vshlq_n_s32(v_r11, 2); int32x4_t v_dst1 = vshrq_n_s32(vaddq_s32(vqaddq_s32(v_r01, shifted), v_delta), 8); vst1q_u16(dst + x, vcombine_u16(vqmovun_s32(v_dst0), vqmovun_s32(v_dst1))); From ef3d02214bc959caed9483ec60fc35f92f7f1040 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 17 Oct 2014 16:32:53 +0400 Subject: [PATCH 5/7] Fixing iOS clang warnings, part 2 --- cmake/OpenCVUtils.cmake | 4 +- modules/core/src/parallel.cpp | 2 +- modules/core/src/persistence.cpp | 4 +- modules/objdetect/src/haar.cpp | 2 +- modules/videoio/src/cap_avfoundation.mm | 40 +++++++++---------- .../videoio/src/cap_ios_abstract_camera.mm | 2 + modules/videoio/src/cap_ios_video_camera.mm | 4 +- .../ios/cmake/Modules/Platform/iOS.cmake | 2 +- 8 files changed, 31 insertions(+), 29 deletions(-) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index b32465ead2..435742dc39 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -249,9 +249,9 @@ macro(add_apple_compiler_options the_module) if("${source}" MATCHES "\\.mm$") get_source_file_property(flags "${source}" COMPILE_FLAGS) if(flags) - set(flags "${_flags} -fobjc-exceptions") + set(flags "${_flags} -fobjc-exceptions -Wno-semicolon-before-method-body") else() - set(flags "-fobjc-exceptions") + set(flags "-fobjc-exceptions -Wno-semicolon-before-method-body") endif() set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}") diff --git a/modules/core/src/parallel.cpp b/modules/core/src/parallel.cpp index 6ebc02df2c..5a51230cef 100644 --- a/modules/core/src/parallel.cpp +++ b/modules/core/src/parallel.cpp @@ -177,7 +177,7 @@ namespace static void block_function(void* context, size_t index) { ProxyLoopBody* ptr_body = static_cast(context); - (*ptr_body)(cv::Range(index, index + 1)); + (*ptr_body)(cv::Range((int)index, (int)index + 1)); } #elif defined HAVE_CONCURRENCY class ProxyLoopBody : public ParallelLoopBodyWrapper diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index 8ee97273e8..fb5648d06f 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -1177,7 +1177,7 @@ force_int: int val, is_hex = d == 'x'; c = ptr[3]; ptr[3] = '\0'; - val = strtol( ptr + is_hex, &endptr, is_hex ? 8 : 16 ); + val = (int)strtol( ptr + is_hex, &endptr, is_hex ? 8 : 16 ); ptr[3] = c; if( endptr == ptr + is_hex ) buf[len++] = 'x'; @@ -2787,7 +2787,7 @@ cvOpenFileStorage( const char* filename, CvMemStorage* dststorage, int flags, co // find the last occurence of for(;;) { - int line_offset = ftell( fs->file ); + int line_offset = (int)ftell( fs->file ); char* ptr0 = icvGets( fs, xml_buf, xml_buf_size ), *ptr; if( !ptr0 ) break; diff --git a/modules/objdetect/src/haar.cpp b/modules/objdetect/src/haar.cpp index b4256111dd..09928264ab 100644 --- a/modules/objdetect/src/haar.cpp +++ b/modules/objdetect/src/haar.cpp @@ -1979,7 +1979,7 @@ cvLoadHaarClassifierCascade( const char* directory, CvSize orig_window_size ) if( !f ) CV_Error( CV_StsError, "" ); fseek( f, 0, SEEK_END ); - size = ftell( f ); + size = (int)ftell( f ); fseek( f, 0, SEEK_SET ); size_t elements_read = fread( ptr, 1, size, f ); CV_Assert(elements_read == (size_t)(size)); diff --git a/modules/videoio/src/cap_avfoundation.mm b/modules/videoio/src/cap_avfoundation.mm index f52700d3b0..29aeeb1c85 100644 --- a/modules/videoio/src/cap_avfoundation.mm +++ b/modules/videoio/src/cap_avfoundation.mm @@ -711,26 +711,26 @@ fromConnection:(AVCaptureConnection *)connection{ memcpy(imagedata, baseaddress, currSize); if (image == NULL) { - image = cvCreateImageHeader(cvSize(width,height), IPL_DEPTH_8U, 4); + image = cvCreateImageHeader(cvSize((int)width,(int)height), IPL_DEPTH_8U, 4); } - image->width =width; - image->height = height; + image->width = (int)width; + image->height = (int)height; image->nChannels = 4; image->depth = IPL_DEPTH_8U; image->widthStep = (int)rowBytes; image->imageData = imagedata; - image->imageSize = currSize; + image->imageSize = (int)currSize; if (bgr_image == NULL) { - bgr_image = cvCreateImageHeader(cvSize(width,height), IPL_DEPTH_8U, 3); + bgr_image = cvCreateImageHeader(cvSize((int)width,(int)height), IPL_DEPTH_8U, 3); } - bgr_image->width =width; - bgr_image->height = height; + bgr_image->width = (int)width; + bgr_image->height = (int)height; bgr_image->nChannels = 3; bgr_image->depth = IPL_DEPTH_8U; bgr_image->widthStep = (int)rowBytes; bgr_image->imageData = bgr_imagedata; - bgr_image->imageSize = currSize; + bgr_image->imageSize = (int)currSize; cvCvtColor(image, bgr_image, CV_BGRA2BGR); @@ -739,7 +739,7 @@ fromConnection:(AVCaptureConnection *)connection{ // iOS provides hardware accelerated rotation through AVCaptureConnection class // I can't get it work. if (bgr_image_r90 == NULL){ - bgr_image_r90 = cvCreateImage(cvSize(height, width), IPL_DEPTH_8U, 3); + bgr_image_r90 = cvCreateImage(cvSize((int)height, (int)width), IPL_DEPTH_8U, 3); } cvTranspose(bgr_image, bgr_image_r90); cvFlip(bgr_image_r90, NULL, 1); @@ -939,29 +939,29 @@ IplImage* CvCaptureFile::retrieveFramePixelBuffer() { memcpy(imagedata, baseaddress, currSize); if (image == NULL) { - image = cvCreateImageHeader(cvSize(width,height), IPL_DEPTH_8U, 4); + image = cvCreateImageHeader(cvSize((int)width,(int)height), IPL_DEPTH_8U, 4); } - image->width =width; - image->height = height; + image->width = (int)width; + image->height = (int)height; image->nChannels = 4; image->depth = IPL_DEPTH_8U; - image->widthStep = rowBytes; + image->widthStep = (int)rowBytes; image->imageData = imagedata; - image->imageSize = currSize; + image->imageSize = (int)currSize; if (bgr_image == NULL) { - bgr_image = cvCreateImageHeader(cvSize(width,height), IPL_DEPTH_8U, 3); + bgr_image = cvCreateImageHeader(cvSize((int)width,(int)height), IPL_DEPTH_8U, 3); } - bgr_image->width =width; - bgr_image->height = height; + bgr_image->width = (int)width; + bgr_image->height = (int)height; bgr_image->nChannels = 3; bgr_image->depth = IPL_DEPTH_8U; - bgr_image->widthStep = rowBytes; + bgr_image->widthStep = (int)rowBytes; bgr_image->imageData = bgr_imagedata; - bgr_image->imageSize = currSize; + bgr_image->imageSize = (int)currSize; cvCvtColor(image, bgr_image,CV_BGRA2BGR); @@ -1262,7 +1262,7 @@ bool CvVideoWriter_AVFoundation::writeFrame(const IplImage* iplimage) { // writer status check if (![mMovieWriterInput isReadyForMoreMediaData] || mMovieWriter.status != AVAssetWriterStatusWriting ) { NSLog(@"[mMovieWriterInput isReadyForMoreMediaData] Not ready for media data or ..."); - NSLog(@"mMovieWriter.status: %d. Error: %@", mMovieWriter.status, [mMovieWriter.error localizedDescription]); + NSLog(@"mMovieWriter.status: %d. Error: %@", (int)mMovieWriter.status, [mMovieWriter.error localizedDescription]); [localpool drain]; return false; } diff --git a/modules/videoio/src/cap_ios_abstract_camera.mm b/modules/videoio/src/cap_ios_abstract_camera.mm index 6af40459ad..3748d910a4 100644 --- a/modules/videoio/src/cap_ios_abstract_camera.mm +++ b/modules/videoio/src/cap_ios_abstract_camera.mm @@ -150,6 +150,7 @@ { [[NSNotificationCenter defaultCenter] removeObserver:self]; [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; + [super dealloc] } @@ -226,6 +227,7 @@ - (void)deviceOrientationDidChange:(NSNotification*)notification { + (void)notification; UIDeviceOrientation orientation = [UIDevice currentDevice].orientation; switch (orientation) diff --git a/modules/videoio/src/cap_ios_video_camera.mm b/modules/videoio/src/cap_ios_video_camera.mm index 4d05f673ae..a75d7b44ed 100644 --- a/modules/videoio/src/cap_ios_video_camera.mm +++ b/modules/videoio/src/cap_ios_video_camera.mm @@ -474,7 +474,7 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;} // check if matrix data pointer or dimensions were changed by the delegate bool iOSimage = false; - if (height == image.rows && width == image.cols && format_opencv == image.type() && bufferAddress == image.data && bytesPerRow == image.step) { + if (height == (size_t)image.rows && width == (size_t)image.cols && format_opencv == image.type() && bufferAddress == image.data && bytesPerRow == image.step) { iOSimage = true; } @@ -592,7 +592,7 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;} ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:[self videoFileURL]]) { [library writeVideoAtPathToSavedPhotosAlbum:[self videoFileURL] - completionBlock:^(NSURL *assetURL, NSError *error){}]; + completionBlock:^(NSURL *assetURL, NSError *error){ (void)assetURL; (void)error; }]; } } diff --git a/platforms/ios/cmake/Modules/Platform/iOS.cmake b/platforms/ios/cmake/Modules/Platform/iOS.cmake index 0db95fb17b..a1ecdeaf3c 100644 --- a/platforms/ios/cmake/Modules/Platform/iOS.cmake +++ b/platforms/ios/cmake/Modules/Platform/iOS.cmake @@ -44,7 +44,7 @@ set (CMAKE_CXX_FLAGS "-stdlib=libc++ -fvisibility=hidden -fvisibility-inlines-hi set (CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3 -fomit-frame-pointer -ffast-math") # Silence some warnings -set (no_warn "-Wno-semicolon-before-method-body -Wno-unused-function -Wno-unused-parameter -Wno-strict-prototypes -Wno-missing-prototypes -Wno-missing-declarations -Wno-unused-const-variable -Wno-overloaded-virtual") +set (no_warn "-Wno-unused-function -Wno-unused-parameter -Wno-strict-prototypes -Wno-missing-prototypes -Wno-missing-declarations -Wno-unused-const-variable -Wno-overloaded-virtual") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${no_warn}") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${no_warn}") # Additional linker flag From 571ebb237314e044aaa82c67d3dc5544097365fe Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 17 Oct 2014 16:46:47 +0400 Subject: [PATCH 6/7] Fixing iOS clang warnings, part 3 --- 3rdparty/zlib/CMakeLists.txt | 2 +- cmake/OpenCVCompilerOptions.cmake | 4 ++++ cmake/OpenCVUtils.cmake | 4 ++-- modules/imgcodecs/src/grfmt_tiff.cpp | 3 ++- modules/videoio/src/cap_ios_abstract_camera.mm | 4 ++-- modules/videoio/src/cap_ios_video_camera.mm | 2 +- platforms/ios/cmake/Modules/Platform/iOS.cmake | 13 ++++--------- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/3rdparty/zlib/CMakeLists.txt b/3rdparty/zlib/CMakeLists.txt index 410f2420bf..853571ef4c 100644 --- a/3rdparty/zlib/CMakeLists.txt +++ b/3rdparty/zlib/CMakeLists.txt @@ -82,7 +82,7 @@ if(UNIX) endif() endif() -ocv_warnings_disable(CMAKE_C_FLAGS -Wattributes -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations) +ocv_warnings_disable(CMAKE_C_FLAGS -Wshorten-64-to-32 -Wattributes -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations) set_target_properties(${ZLIB_LIBRARY} PROPERTIES OUTPUT_NAME ${ZLIB_LIBRARY} diff --git a/cmake/OpenCVCompilerOptions.cmake b/cmake/OpenCVCompilerOptions.cmake index ba74ebe4ab..909e2a471c 100644 --- a/cmake/OpenCVCompilerOptions.cmake +++ b/cmake/OpenCVCompilerOptions.cmake @@ -106,6 +106,10 @@ if(CMAKE_COMPILER_IS_GNUCXX) add_extra_compiler_option(-march=i686) endif() + if(APPLE) + add_extra_compiler_option(-Wno-semicolon-before-method-body) + endif() + # Other optimizations if(ENABLE_OMIT_FRAME_POINTER) add_extra_compiler_option(-fomit-frame-pointer) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 435742dc39..b32465ead2 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -249,9 +249,9 @@ macro(add_apple_compiler_options the_module) if("${source}" MATCHES "\\.mm$") get_source_file_property(flags "${source}" COMPILE_FLAGS) if(flags) - set(flags "${_flags} -fobjc-exceptions -Wno-semicolon-before-method-body") + set(flags "${_flags} -fobjc-exceptions") else() - set(flags "-fobjc-exceptions -Wno-semicolon-before-method-body") + set(flags "-fobjc-exceptions") endif() set_source_files_properties("${source}" PROPERTIES COMPILE_FLAGS "${flags}") diff --git a/modules/imgcodecs/src/grfmt_tiff.cpp b/modules/imgcodecs/src/grfmt_tiff.cpp index 00e1d30f33..7ec76c8483 100644 --- a/modules/imgcodecs/src/grfmt_tiff.cpp +++ b/modules/imgcodecs/src/grfmt_tiff.cpp @@ -52,10 +52,11 @@ namespace cv { static const char fmtSignTiffII[] = "II\x2a\x00"; -static const char fmtSignTiffMM[] = "MM\x00\x2a"; #ifdef HAVE_TIFF +static const char fmtSignTiffMM[] = "MM\x00\x2a"; + #include "tiff.h" #include "tiffio.h" diff --git a/modules/videoio/src/cap_ios_abstract_camera.mm b/modules/videoio/src/cap_ios_abstract_camera.mm index 3748d910a4..1ded46a99f 100644 --- a/modules/videoio/src/cap_ios_abstract_camera.mm +++ b/modules/videoio/src/cap_ios_abstract_camera.mm @@ -150,7 +150,7 @@ { [[NSNotificationCenter defaultCenter] removeObserver:self]; [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; - [super dealloc] + [super dealloc]; } @@ -244,7 +244,7 @@ default: break; } - NSLog(@"deviceOrientationDidChange: %d", orientation); + NSLog(@"deviceOrientationDidChange: %d", (int)orientation); [self updateOrientation]; } diff --git a/modules/videoio/src/cap_ios_video_camera.mm b/modules/videoio/src/cap_ios_video_camera.mm index a75d7b44ed..152fc80643 100644 --- a/modules/videoio/src/cap_ios_video_camera.mm +++ b/modules/videoio/src/cap_ios_video_camera.mm @@ -464,7 +464,7 @@ static CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;} } // delegate image processing to the delegate - cv::Mat image(height, width, format_opencv, bufferAddress, bytesPerRow); + cv::Mat image((int)height, (int)width, format_opencv, bufferAddress, bytesPerRow); CGImage* dstImage; diff --git a/platforms/ios/cmake/Modules/Platform/iOS.cmake b/platforms/ios/cmake/Modules/Platform/iOS.cmake index a1ecdeaf3c..3a80e84ae1 100644 --- a/platforms/ios/cmake/Modules/Platform/iOS.cmake +++ b/platforms/ios/cmake/Modules/Platform/iOS.cmake @@ -39,16 +39,11 @@ set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSI set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}") # Hidden visibilty is required for cxx on iOS -set (CMAKE_C_FLAGS "") -set (CMAKE_CXX_FLAGS "-stdlib=libc++ -fvisibility=hidden -fvisibility-inlines-hidden") -set (CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3 -fomit-frame-pointer -ffast-math") +set (no_warn "-Wno-unused-function -Wno-overloaded-virtual") +set (CMAKE_C_FLAGS "${no_warn}") +set (CMAKE_CXX_FLAGS "-stdlib=libc++ -fvisibility=hidden -fvisibility-inlines-hidden ${no_warn}") -# Silence some warnings -set (no_warn "-Wno-unused-function -Wno-unused-parameter -Wno-strict-prototypes -Wno-missing-prototypes -Wno-missing-declarations -Wno-unused-const-variable -Wno-overloaded-virtual") -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${no_warn}") -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${no_warn}") -# Additional linker flag -set (CMAKE_CXX_LINK_FLAGS "-Wl,-headerpad_max_install_names ${CMAKE_CXX_LINK_FLAGS}") +set (CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3 -fomit-frame-pointer -ffast-math") if (HAVE_FLAG_SEARCH_PATHS_FIRST) set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}") From 276bed3e4aaf0ed913ff27d9338e3a1ba9942496 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Fri, 17 Oct 2014 18:29:30 +0400 Subject: [PATCH 7/7] final fix --- modules/stitching/src/matchers.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index 94b7883959..565d4ffeda 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -346,6 +346,11 @@ SurfFeaturesFinder::SurfFeaturesFinder(double hess_thresh, int num_octaves, int extractor_->set(SURF::NOCTAVE_LAYERS, num_layers_descr); } #else + (void)hess_thresh; + (void)num_octaves; + (void)num_layers; + (void)num_octaves_descr; + (void)num_layers_descr; CV_Error( Error::StsNotImplemented, "OpenCV was built without SURF support" ); #endif }