diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index 059612d6de..c93415c326 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -1836,7 +1836,9 @@ icvGenerateQuads( CvCBQuad **out_quads, CvCBCorner **out_corners, assert( src_contour->total == 4 ); for( i = 0; i < 4; i++ ) { - CvPoint2D32f pt = cvPointTo32f(*(CvPoint*)cvGetSeqElem(src_contour, i)); + CvPoint * onePoint = (CvPoint*)cvGetSeqElem(src_contour, i); + CV_Assert(onePoint != NULL); + CvPoint2D32f pt = cvPointTo32f(*onePoint); CvCBCorner* corner = &(*out_corners)[quad_count*4 + i]; memset( corner, 0, sizeof(*corner) ); diff --git a/modules/core/src/datastructs.cpp b/modules/core/src/datastructs.cpp index d69565f4c2..56528fcf69 100644 --- a/modules/core/src/datastructs.cpp +++ b/modules/core/src/datastructs.cpp @@ -2882,7 +2882,7 @@ cvGraphRemoveEdgeByPtr( CvGraph* graph, CvGraphVtx* start_vtx, CvGraphVtx* end_v break; } - assert( edge != 0 ); + CV_Assert( edge != 0 ); next_edge = edge->next[ofs]; if( prev_edge ) diff --git a/modules/core/src/opencl/runtime/opencl_core.cpp b/modules/core/src/opencl/runtime/opencl_core.cpp index dc3d0a4403..5c466114ff 100644 --- a/modules/core/src/opencl/runtime/opencl_core.cpp +++ b/modules/core/src/opencl/runtime/opencl_core.cpp @@ -257,14 +257,14 @@ static void* opencl_check_fn(int ID) const struct DynamicFnEntry* e = NULL; if (ID < CUSTOM_FUNCTION_ID) { - assert(ID >= 0 && ID < (int)(sizeof(opencl_fn_list)/sizeof(opencl_fn_list[0]))); + CV_Assert(ID >= 0 && ID < (int)(sizeof(opencl_fn_list)/sizeof(opencl_fn_list[0]))); e = opencl_fn_list[ID]; } #ifdef HAVE_OPENCL_SVM else if (ID >= SVM_FUNCTION_ID_START && ID < SVM_FUNCTION_ID_END) { ID = ID - SVM_FUNCTION_ID_START; - assert(ID >= 0 && ID < (int)(sizeof(opencl_svm_fn_list)/sizeof(opencl_svm_fn_list[0]))); + CV_Assert(ID >= 0 && ID < (int)(sizeof(opencl_svm_fn_list)/sizeof(opencl_svm_fn_list[0]))); e = opencl_svm_fn_list[ID]; } #endif diff --git a/modules/imgproc/src/contours.cpp b/modules/imgproc/src/contours.cpp index 77af291a73..ea56051c2b 100644 --- a/modules/imgproc/src/contours.cpp +++ b/modules/imgproc/src/contours.cpp @@ -1179,7 +1179,7 @@ cvFindNextContour( CvContourScanner scanner ) cur = cur->next; } - assert( par_info != 0 ); + CV_Assert( par_info != 0 ); /* if current contour is a hole and previous contour is a hole or current contour is external and previous contour is external then diff --git a/modules/imgproc/src/convhull.cpp b/modules/imgproc/src/convhull.cpp index c3287b8931..e56d3cbcec 100644 --- a/modules/imgproc/src/convhull.cpp +++ b/modules/imgproc/src/convhull.cpp @@ -404,9 +404,6 @@ CV_IMPL CvSeq* cvConvexHull2( const CvArr* array, void* hull_storage, int orientation, int return_points ) { - union { CvContour* c; CvSeq* s; } hull; - hull.s = 0; - CvMat* mat = 0; CvContour contour_header; CvSeq hull_header; @@ -427,7 +424,9 @@ cvConvexHull2( const CvArr* array, void* hull_storage, ptseq = cvPointSeqFromMat( CV_SEQ_KIND_GENERIC, array, &contour_header, &block ); } - if( CV_IS_STORAGE( hull_storage )) + bool isStorage = isStorageOrMat(hull_storage); + + if(isStorage) { if( return_points ) { @@ -445,9 +444,6 @@ cvConvexHull2( const CvArr* array, void* hull_storage, } else { - if( !CV_IS_MAT( hull_storage )) - CV_Error(CV_StsBadArg, "Destination must be valid memory storage or matrix"); - mat = (CvMat*)hull_storage; if( (mat->cols != 1 && mat->rows != 1) || !CV_IS_MAT_CONT(mat->type)) @@ -473,10 +469,10 @@ cvConvexHull2( const CvArr* array, void* hull_storage, int total = ptseq->total; if( total == 0 ) { - if( mat ) + if( !isStorage ) CV_Error( CV_StsBadSize, "Point sequence can not be empty if the output is matrix" ); - return hull.s; + return 0; } cv::AutoBuffer _ptbuf; @@ -498,22 +494,18 @@ cvConvexHull2( const CvArr* array, void* hull_storage, else cvSeqPushMulti(hullseq, h0.ptr(), (int)h0.total()); - if( mat ) + if (isStorage) + { + return hullseq; + } + else { if( mat->rows > mat->cols ) mat->rows = hullseq->total; else mat->cols = hullseq->total; + return 0; } - else - { - hull.s = hullseq; - hull.c->rect = cvBoundingRect( ptseq, - ptseq->header_size < (int)sizeof(CvContour) || - &ptseq->flags == &contour_header.flags ); - } - - return hull.s; } diff --git a/modules/imgproc/src/hough.cpp b/modules/imgproc/src/hough.cpp index 6850499e65..665e9a3af8 100644 --- a/modules/imgproc/src/hough.cpp +++ b/modules/imgproc/src/hough.cpp @@ -894,7 +894,6 @@ cvHoughLines2( CvArr* src_image, void* lineStorage, int method, cv::Mat image = cv::cvarrToMat(src_image); std::vector l2; std::vector l4; - CvSeq* result = 0; CvMat* mat = 0; CvSeq* lines = 0; @@ -921,11 +920,13 @@ cvHoughLines2( CvArr* src_image, void* lineStorage, int method, elemSize = sizeof(int)*4; } - if( CV_IS_STORAGE( lineStorage )) + bool isStorage = isStorageOrMat(lineStorage); + + if( isStorage ) { lines = cvCreateSeq( lineType, sizeof(CvSeq), elemSize, (CvMemStorage*)lineStorage ); } - else if( CV_IS_MAT( lineStorage )) + else { mat = (CvMat*)lineStorage; @@ -942,8 +943,6 @@ cvHoughLines2( CvArr* src_image, void* lineStorage, int method, linesMax = lines->total; cvClearSeq( lines ); } - else - CV_Error( CV_StsBadArg, "Destination is not CvMemStorage* nor CvMat*" ); iparam1 = cvRound(param1); iparam2 = cvRound(param2); @@ -968,7 +967,7 @@ cvHoughLines2( CvArr* src_image, void* lineStorage, int method, int nlines = (int)(l2.size() + l4.size()); - if( mat ) + if( !isStorage ) { if( mat->cols > mat->rows ) mat->cols = nlines; @@ -981,20 +980,20 @@ cvHoughLines2( CvArr* src_image, void* lineStorage, int method, cv::Mat lx = method == CV_HOUGH_STANDARD || method == CV_HOUGH_MULTI_SCALE ? cv::Mat(nlines, 1, CV_32FC2, &l2[0]) : cv::Mat(nlines, 1, CV_32SC4, &l4[0]); - if( mat ) + if (isStorage) + { + cvSeqPushMulti(lines, lx.ptr(), nlines); + } + else { cv::Mat dst(nlines, 1, lx.type(), mat->data.ptr); lx.copyTo(dst); } - else - { - cvSeqPushMulti(lines, lx.ptr(), nlines); - } } - if( !mat ) - result = lines; - return result; + if( isStorage ) + return lines; + return 0; } @@ -1227,8 +1226,6 @@ cvHoughCircles( CvArr* src_image, void* circle_storage, double param1, double param2, int min_radius, int max_radius ) { - CvSeq* result = 0; - CvMat stub, *img = (CvMat*)src_image; CvMat* mat = 0; CvSeq* circles = 0; @@ -1255,12 +1252,14 @@ cvHoughCircles( CvArr* src_image, void* circle_storage, else if( max_radius <= min_radius ) max_radius = min_radius + 2; - if( CV_IS_STORAGE( circle_storage )) + bool isStorage = isStorageOrMat(circle_storage); + + if(isStorage) { circles = cvCreateSeq( CV_32FC3, sizeof(CvSeq), sizeof(float)*3, (CvMemStorage*)circle_storage ); } - else if( CV_IS_MAT( circle_storage )) + else { mat = (CvMat*)circle_storage; @@ -1274,8 +1273,6 @@ cvHoughCircles( CvArr* src_image, void* circle_storage, circles_max = circles->total; cvClearSeq( circles ); } - else - CV_Error( CV_StsBadArg, "Destination is not CvMemStorage* nor CvMat*" ); switch( method ) { @@ -1288,17 +1285,17 @@ cvHoughCircles( CvArr* src_image, void* circle_storage, CV_Error( CV_StsBadArg, "Unrecognized method id" ); } - if( mat ) + if (isStorage) + return circles; + else { if( mat->cols > mat->rows ) mat->cols = circles->total; else mat->rows = circles->total; } - else - result = circles; - return result; + return 0; } diff --git a/modules/imgproc/src/precomp.hpp b/modules/imgproc/src/precomp.hpp index 40598a083e..55241d9b88 100644 --- a/modules/imgproc/src/precomp.hpp +++ b/modules/imgproc/src/precomp.hpp @@ -69,7 +69,7 @@ /* helper tables */ extern const uchar icvSaturate8u_cv[]; -#define CV_FAST_CAST_8U(t) (assert(-256 <= (t) && (t) <= 512), icvSaturate8u_cv[(t)+256]) +#define CV_FAST_CAST_8U(t) ( (-256 <= (t) && (t) <= 512) ? icvSaturate8u_cv[(t)+256] : 0 ) #define CV_CALC_MIN_8U(a,b) (a) -= CV_FAST_CAST_8U((a) - (b)) #define CV_CALC_MAX_8U(a,b) (a) += CV_FAST_CAST_8U((b) - (a)) @@ -111,4 +111,15 @@ static inline IppiInterpolationType ippiGetInterpolation(int inter) #include "opencv2/core/sse_utils.hpp" +inline bool isStorageOrMat(void * arr) +{ + if (CV_IS_STORAGE( arr )) + return true; + else if (CV_IS_MAT( arr )) + return false; + else + CV_Error( CV_StsBadArg, "Destination is not CvMemStorage* nor CvMat*" ); + return false; +} + #endif /*__OPENCV_CV_INTERNAL_H_*/ diff --git a/modules/imgproc/src/templmatch.cpp b/modules/imgproc/src/templmatch.cpp index ce5c4d74cc..302e26ef67 100644 --- a/modules/imgproc/src/templmatch.cpp +++ b/modules/imgproc/src/templmatch.cpp @@ -477,6 +477,7 @@ static bool matchTemplate_CCOEFF_NORMED(InputArray _image, InputArray _templ, Ou integral(_image, image_sums, image_sqsums, CV_32F, CV_32F); int type = image_sums.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type); + CV_Assert(cn >= 1 && cn <= 4); ocl::Kernel k("matchTemplate_CCOEFF_NORMED", ocl::imgproc::match_template_oclsrc, format("-D CCOEFF_NORMED -D T=%s -D T1=%s -D cn=%d", ocl::typeToStr(type), ocl::typeToStr(depth), cn)); diff --git a/modules/objdetect/src/haar.cpp b/modules/objdetect/src/haar.cpp index cb24479aa0..6b1c8b8ebf 100644 --- a/modules/objdetect/src/haar.cpp +++ b/modules/objdetect/src/haar.cpp @@ -1879,7 +1879,7 @@ icvLoadCascadeCART( const char** input_cascade, int n, CvSize orig_window_size ) sscanf( stage, "%d%n", &rects, &dl ); stage += dl; - CV_DbgAssert( rects >= 2 && rects <= CV_HAAR_FEATURE_MAX ); + CV_Assert( rects >= 2 && rects <= CV_HAAR_FEATURE_MAX ); for( k = 0; k < rects; k++ ) { diff --git a/modules/photo/src/calibrate.cpp b/modules/photo/src/calibrate.cpp index a0e07c0456..8aa96f5ae9 100644 --- a/modules/photo/src/calibrate.cpp +++ b/modules/photo/src/calibrate.cpp @@ -224,6 +224,7 @@ public: int channels = images[0].channels(); int CV_32FCC = CV_MAKETYPE(CV_32F, channels); + CV_Assert(channels >= 1 && channels <= 3); dst.create(LDR_SIZE, 1, CV_32FCC); Mat response = dst.getMat();