From e0a309f4a83c14bad0c8ebd56a30a942bd451a10 Mon Sep 17 00:00:00 2001 From: William Durand Date: Thu, 15 Mar 2018 11:24:57 +0100 Subject: [PATCH] Astyle cpp/h files --- contrib/face.cpp | 14 ++-- contrib/tracking.cpp | 20 +++--- contrib/tracking.h | 2 +- contrib/xfeatures2d.cpp | 36 +++++++---- core.cpp | 24 ++++--- core.h | 138 ++++++++++++++++++++-------------------- dnn.cpp | 3 +- dnn.h | 3 +- features2d.cpp | 117 ++++++++++++++++++++++------------ highgui.cpp | 8 ++- imgcodecs.cpp | 5 +- imgproc.cpp | 110 +++++++++++++++++++------------- imgproc.h | 9 ++- objdetect.cpp | 49 ++++++++------ objdetect.h | 5 +- pvl/face.cpp | 36 ++++------- pvl/face_detector.cpp | 26 +++----- pvl/face_recognizer.cpp | 22 ++++--- pvl/face_recognizer.h | 6 +- version.cpp | 2 +- version.h | 2 +- video.cpp | 7 +- video.h | 4 +- videoio.cpp | 6 +- videoio.h | 2 +- 25 files changed, 378 insertions(+), 278 deletions(-) diff --git a/contrib/face.cpp b/contrib/face.cpp index a8e53f7f..19bf7833 100644 --- a/contrib/face.cpp +++ b/contrib/face.cpp @@ -1,16 +1,18 @@ #include "face.h" LBPHFaceRecognizer CreateLBPHFaceRecognizer() { - return new cv::Ptr(cv::face::LBPHFaceRecognizer::create()); + return new cv::Ptr(cv::face::LBPHFaceRecognizer::create()); } void LBPHFaceRecognizer_Train(LBPHFaceRecognizer fr, Mats mats, IntVector labels_in) { std::vector labels; - for(int i = 0, *v = labels_in.val; i < labels_in.length; ++v, ++i) { + + for (int i = 0, *v = labels_in.val; i < labels_in.length; ++v, ++i) { labels.push_back(*v); } std::vector images; + for (int i = 0; i < mats.length; ++i) { images.push_back(*mats.mats[i]); } @@ -22,11 +24,13 @@ void LBPHFaceRecognizer_Train(LBPHFaceRecognizer fr, Mats mats, IntVector labels void LBPHFaceRecognizer_Update(LBPHFaceRecognizer fr, Mats mats, IntVector labels_in) { std::vector labels; - for(int i = 0, *v = labels_in.val; i < labels_in.length; ++v, ++i) { + + for (int i = 0, *v = labels_in.val; i < labels_in.length; ++v, ++i) { labels.push_back(*v); } std::vector images; + for (int i = 0; i < mats.length; ++i) { images.push_back(*mats.mats[i]); } @@ -49,8 +53,8 @@ struct PredictResponse LBPHFaceRecognizer_PredictExtended(LBPHFaceRecognizer fr, double confidence; (*fr)->predict(*sample, label, confidence); - response.label = label; - response.confidence = confidence; + response.label = label; + response.confidence = confidence; return response; diff --git a/contrib/tracking.cpp b/contrib/tracking.cpp index 684f5631..bd77539d 100644 --- a/contrib/tracking.cpp +++ b/contrib/tracking.cpp @@ -9,7 +9,7 @@ bool Tracker_Init(Tracker self, Mat image, Rect boundingBox) { return ret; } -bool Tracker_Update(Tracker self, Mat image, Rect *boundingBox) { +bool Tracker_Update(Tracker self, Mat image, Rect* boundingBox) { cv::Rect2d bb; bool ret = (*self)->update(*image, bb); boundingBox->x = int(bb.x); @@ -23,7 +23,7 @@ TrackerMIL TrackerMIL_Create() { return new cv::Ptr(cv::TrackerMIL::create()); } -void TrackerMIL_Close(TrackerMIL self){ +void TrackerMIL_Close(TrackerMIL self) { delete self; } @@ -31,23 +31,23 @@ TrackerBoosting TrackerBoosting_Create() { return new cv::Ptr(cv::TrackerBoosting::create()); } -void TrackerBoosting_Close(TrackerBoosting self){ - delete self; +void TrackerBoosting_Close(TrackerBoosting self) { + delete self; } TrackerMedianFlow TrackerMedianFlow_Create() { return new cv::Ptr(cv::TrackerMedianFlow::create()); } -void TrackerMedianFlow_Close(TrackerMedianFlow self){ - delete self; +void TrackerMedianFlow_Close(TrackerMedianFlow self) { + delete self; } TrackerTLD TrackerTLD_Create() { return new cv::Ptr(cv::TrackerTLD::create()); } -void TrackerTLD_Close(TrackerTLD self){ +void TrackerTLD_Close(TrackerTLD self) { delete self; } @@ -55,7 +55,7 @@ TrackerKCF TrackerKCF_Create() { return new cv::Ptr(cv::TrackerKCF::create()); } -void TrackerKCF_Close(TrackerKCF self){ +void TrackerKCF_Close(TrackerKCF self) { delete self; } @@ -63,7 +63,7 @@ TrackerMOSSE TrackerMOSSE_Create() { return new cv::Ptr(cv::TrackerMOSSE::create()); } -void TrackerMOSSE_Close(TrackerMOSSE self){ +void TrackerMOSSE_Close(TrackerMOSSE self) { delete self; } @@ -71,6 +71,6 @@ TrackerCSRT TrackerCSRT_Create() { return new cv::Ptr(cv::TrackerCSRT::create()); } -void TrackerCSRT_Close(TrackerCSRT self){ +void TrackerCSRT_Close(TrackerCSRT self) { delete self; } diff --git a/contrib/tracking.h b/contrib/tracking.h index 32f353ee..0a19008c 100644 --- a/contrib/tracking.h +++ b/contrib/tracking.h @@ -32,7 +32,7 @@ typedef void* TrackerCSRT; #endif bool Tracker_Init(Tracker self, Mat image, Rect boundingBox); -bool Tracker_Update(Tracker self, Mat image, Rect *boundingBox); +bool Tracker_Update(Tracker self, Mat image, Rect* boundingBox); TrackerMIL TrackerMIL_Create(); void TrackerMIL_Close(TrackerMIL self); diff --git a/contrib/xfeatures2d.cpp b/contrib/xfeatures2d.cpp index b9bb0d99..7197cf28 100644 --- a/contrib/xfeatures2d.cpp +++ b/contrib/xfeatures2d.cpp @@ -14,11 +14,14 @@ struct KeyPoints SIFT_Detect(SIFT d, Mat src) { (*d)->detect(*src, detected); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -28,11 +31,14 @@ struct KeyPoints SIFT_DetectAndCompute(SIFT d, Mat src, Mat mask, Mat desc) { (*d)->detectAndCompute(*src, *mask, detected, *desc); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -51,11 +57,14 @@ struct KeyPoints SURF_Detect(SURF d, Mat src) { (*d)->detect(*src, detected); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -65,11 +74,14 @@ struct KeyPoints SURF_DetectAndCompute(SURF d, Mat src, Mat mask, Mat desc) { (*d)->detectAndCompute(*src, *mask, detected, *desc); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } diff --git a/core.cpp b/core.cpp index c42ab0a0..725d2c0f 100644 --- a/core.cpp +++ b/core.cpp @@ -53,7 +53,7 @@ void Mat_ConvertTo(Mat m, Mat dst, int type) { // Mat_ToBytes returns the bytes representation of the underlying data. struct ByteArray Mat_ToBytes(Mat m) { - return toByteArray(reinterpret_cast(m->data), m->total() * m->elemSize()); + return toByteArray(reinterpret_cast(m->data), m->total() * m->elemSize()); } // Mat_Region returns a Mat of a region of another Mat @@ -84,7 +84,7 @@ Scalar Mat_Mean(Mat m) { } void LUT(Mat src, Mat lut, Mat dst) { - cv::LUT(*src, *lut, *dst); + cv::LUT(*src, *lut, *dst); } // Mat_Rows returns how many rows in this Mat. @@ -119,7 +119,7 @@ uint8_t Mat_GetUChar(Mat m, int row, int col) { } uint8_t Mat_GetUChar3(Mat m, int x, int y, int z) { - return m->at(x, y , z); + return m->at(x, y, z); } // Mat_GetSChar returns a specific row/col value from this Mat expecting @@ -185,11 +185,11 @@ void Mat_SetUChar3(Mat m, int x, int y, int z, uint8_t val) { // Mat_SetSChar set a specific row/col value from this Mat expecting // each element to contain a schar aka CV_8S. void Mat_SetSChar(Mat m, int row, int col, int8_t val) { - m->at(row, col) = val; + m->at(row, col) = val; } void Mat_SetSChar3(Mat m, int x, int y, int z, int8_t val) { - m->at(x, y, z) = val; + m->at(x, y, z) = val; } // Mat_SetShort set a specific row/col value from this Mat expecting @@ -260,7 +260,8 @@ void Mat_BitwiseXor(Mat src1, Mat src2, Mat dst) { cv::bitwise_xor(*src1, *src2, *dst); } -void Mat_BatchDistance(Mat src1, Mat src2, Mat dist, int dtype, Mat nidx, int normType, int K, Mat mask, int update, bool crosscheck) { +void Mat_BatchDistance(Mat src1, Mat src2, Mat dist, int dtype, Mat nidx, int normType, int K, + Mat mask, int update, bool crosscheck) { cv::batchDistance(*src1, *src2, *dist, dtype, *nidx, normType, K, *mask, update, crosscheck); } @@ -293,7 +294,8 @@ void Mat_ConvertScaleAbs(Mat src, Mat dst, double alpha, double beta) { cv::convertScaleAbs(*src, *dst, alpha, beta); } -void Mat_CopyMakeBorder(Mat src, Mat dst, int top, int bottom, int left, int right, int borderType, Scalar value) { +void Mat_CopyMakeBorder(Mat src, Mat dst, int top, int bottom, int left, int right, int borderType, + Scalar value) { cv::Scalar c_value(value.val1, value.val2, value.val3, value.val4); cv::copyMakeBorder(*src, *dst, top, bottom, left, right, borderType, c_value); } @@ -381,9 +383,11 @@ void Mat_MeanStdDev(Mat src, Mat dstMean, Mat dstStdDev) { void Mat_Merge(struct Mats mats, Mat dst) { std::vector images; + for (int i = 0; i < mats.length; ++i) { images.push_back(*mats.mats[i]); } + cv::merge(images, *dst); } @@ -410,13 +414,15 @@ double Norm(Mat src1, int normType) { return cv::norm(*src1, normType); } -void Mat_Split(Mat src, struct Mats *mats) { +void Mat_Split(Mat src, struct Mats* mats) { std::vector channels; cv::split(*src, channels); mats->mats = new Mat[channels.size()]; + for (size_t i = 0; i < channels.size(); ++i) { mats->mats[i] = new cv::Mat(channels[i]); } + mats->length = (int)channels.size(); } @@ -448,6 +454,7 @@ void Contours_Close(struct Contours cs) { for (int i = 0; i < cs.length; i++) { Points_Close(cs.contours[i]); } + delete[] cs.contours; } @@ -459,6 +466,7 @@ void Points_Close(Points ps) { for (size_t i = 0; i < ps.length; i++) { Point_Close(ps.points[i]); } + delete[] ps.points; } diff --git a/core.h b/core.h index e8f74e40..05c72e9a 100644 --- a/core.h +++ b/core.h @@ -5,19 +5,19 @@ #include typedef struct String { - const char* str; - int length; + const char* str; + int length; } String; -typedef struct ByteArray{ - char *data; - int length; +typedef struct ByteArray { + char* data; + int length; } ByteArray; // Wrapper for std::vector typedef struct IntVector { - int *val; - int length; + int* val; + int length; } IntVector; #ifdef __cplusplus @@ -26,21 +26,21 @@ extern "C" { #endif typedef struct RawData { - int width; - int height; - struct ByteArray data; + int width; + int height; + struct ByteArray data; } RawData; // Wrapper for an individual cv::cvPoint typedef struct Point { - int x; - int y; + int x; + int y; } Point; // Wrapper for the vector of Point structs aka std::vector typedef struct Points { - Point* points; - int length; + Point* points; + int length; } Points; // Contour is alias for Points @@ -48,83 +48,83 @@ typedef Points Contour; // Wrapper for the vector of Points vectors aka std::vector< std::vector > typedef struct Contours { - Contour* contours; - int length; + Contour* contours; + int length; } Contours; // Wrapper for an individual cv::cvRect typedef struct Rect { - int x; - int y; - int width; - int height; + int x; + int y; + int width; + int height; } Rect; // Wrapper for the vector of Rect struct aka std::vector typedef struct Rects { - Rect* rects; - int length; + Rect* rects; + int length; } Rects; // Wrapper for an individual cv::cvSize typedef struct Size { - int width; - int height; + int width; + int height; } Size; // Wrapper for an individual cv::cvScalar typedef struct Scalar { - double val1; - double val2; - double val3; - double val4; + double val1; + double val2; + double val3; + double val4; } Scalar; // Wrapper for a individual cv::KeyPoint typedef struct KeyPoint { - double x; - double y; - double size; - double angle; - double response; - int octave; - int classID; + double x; + double y; + double size; + double angle; + double response; + int octave; + int classID; } KeyPoint; // Wrapper for the vector of KeyPoint struct aka std::vector typedef struct KeyPoints { - KeyPoint* keypoints; - int length; + KeyPoint* keypoints; + int length; } KeyPoints; // Wrapper for an individual cv::Moment typedef struct Moment { - double m00; - double m10; - double m01; - double m20; - double m11; - double m02; - double m30; - double m21; - double m12; - double m03; - - double mu20; - double mu11; - double mu02; - double mu30; - double mu21; - double mu12; - double mu03; - - double nu20; - double nu11; - double nu02; - double nu30; - double nu21; - double nu12; - double nu03; + double m00; + double m10; + double m01; + double m20; + double m11; + double m02; + double m30; + double m21; + double m12; + double m03; + + double mu20; + double mu11; + double mu02; + double mu30; + double mu21; + double mu12; + double mu03; + + double nu20; + double nu11; + double nu02; + double nu30; + double nu21; + double nu12; + double nu03; } Moment; #ifdef __cplusplus @@ -137,8 +137,8 @@ typedef void* TermCriteria; // Wrapper for the vector of Mat aka std::vector typedef struct Mats { - Mat* mats; - int length; + Mat* mats; + int length; } Mats; Mat Mats_get(struct Mats mats, int i); @@ -210,13 +210,15 @@ void Mat_BitwiseNot(Mat src1, Mat dst); void Mat_BitwiseOr(Mat src1, Mat src2, Mat dst); void Mat_BitwiseXor(Mat src1, Mat src2, Mat dst); void Mat_Compare(Mat src1, Mat src2, Mat dst, int ct); -void Mat_BatchDistance(Mat src1, Mat src2, Mat dist, int dtype, Mat nidx, int normType, int K, Mat mask, int update, bool crosscheck); +void Mat_BatchDistance(Mat src1, Mat src2, Mat dist, int dtype, Mat nidx, int normType, int K, + Mat mask, int update, bool crosscheck); int Mat_BorderInterpolate(int p, int len, int borderType); void Mat_CalcCovarMatrix(Mat samples, Mat covar, Mat mean, int flags, int ctype); void Mat_CartToPolar(Mat x, Mat y, Mat magnitude, Mat angle, bool angleInDegrees); void Mat_CompleteSymm(Mat m, bool lowerToUpper); void Mat_ConvertScaleAbs(Mat src, Mat dst, double alpha, double beta); -void Mat_CopyMakeBorder(Mat src, Mat dst, int top, int bottom, int left, int right, int borderType, Scalar value); +void Mat_CopyMakeBorder(Mat src, Mat dst, int top, int bottom, int left, int right, int borderType, + Scalar value); int Mat_CountNonZero(Mat src); void Mat_DCT(Mat src, Mat dst, int flags); void Mat_DFT(Mat m, Mat dst, int flags); @@ -244,7 +246,7 @@ void Mat_Multiply(Mat src1, Mat src2, Mat dst); void Mat_Subtract(Mat src1, Mat src2, Mat dst); void Mat_Normalize(Mat src, Mat dst, double alpha, double beta, int typ); double Norm(Mat src1, int normType); -void Mat_Split(Mat src, struct Mats *mats); +void Mat_Split(Mat src, struct Mats* mats); void Mat_Subtract(Mat src1, Mat src2, Mat dst); void Mat_Pow(Mat src, double power, Mat dst); Scalar Mat_Sum(Mat src1); diff --git a/dnn.cpp b/dnn.cpp index 0fdb0105..dcfba5b6 100644 --- a/dnn.cpp +++ b/dnn.cpp @@ -26,7 +26,8 @@ Mat Net_Forward(Net net, const char* outputName) { return new cv::Mat(net->forward(outputName)); } -Mat Net_BlobFromImage(Mat image, double scalefactor, Size size, Scalar mean, bool swapRB, bool crop) { +Mat Net_BlobFromImage(Mat image, double scalefactor, Size size, Scalar mean, bool swapRB, + bool crop) { cv::Size sz(size.width, size.height); cv::Scalar cm = cv::Scalar(mean.val1, mean.val2, mean.val3, mean.val4); diff --git a/dnn.h b/dnn.h index db721a5a..69ffc59b 100644 --- a/dnn.h +++ b/dnn.h @@ -19,7 +19,8 @@ typedef void* Net; Net Net_ReadNetFromCaffe(const char* prototxt, const char* caffeModel); Net Net_ReadNetFromTensorflow(const char* model); -Mat Net_BlobFromImage(Mat image, double scalefactor, Size size, Scalar mean, bool swapRB, bool crop); +Mat Net_BlobFromImage(Mat image, double scalefactor, Size size, Scalar mean, bool swapRB, + bool crop); void Net_Close(Net net); bool Net_Empty(Net net); void Net_SetInput(Net net, Mat blob, const char* name); diff --git a/features2d.cpp b/features2d.cpp index dc80f161..42be945c 100644 --- a/features2d.cpp +++ b/features2d.cpp @@ -14,11 +14,14 @@ struct KeyPoints AKAZE_Detect(AKAZE a, Mat src) { (*a)->detect(*src, detected); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -28,11 +31,14 @@ struct KeyPoints AKAZE_DetectAndCompute(AKAZE a, Mat src, Mat mask, Mat desc) { (*a)->detectAndCompute(*src, *mask, detected, *desc); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -51,11 +57,14 @@ struct KeyPoints AgastFeatureDetector_Detect(AgastFeatureDetector a, Mat src) { (*a)->detect(*src, detected); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -74,11 +83,14 @@ struct KeyPoints BRISK_Detect(BRISK b, Mat src) { (*b)->detect(*src, detected); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -88,11 +100,14 @@ struct KeyPoints BRISK_DetectAndCompute(BRISK b, Mat src, Mat mask, Mat desc) { (*b)->detectAndCompute(*src, *mask, detected, *desc); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -111,11 +126,14 @@ struct KeyPoints GFTTDetector_Detect(GFTTDetector a, Mat src) { (*a)->detect(*src, detected); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -134,11 +152,14 @@ struct KeyPoints KAZE_Detect(KAZE a, Mat src) { (*a)->detect(*src, detected); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -148,11 +169,14 @@ struct KeyPoints KAZE_DetectAndCompute(KAZE a, Mat src, Mat mask, Mat desc) { (*a)->detectAndCompute(*src, *mask, detected, *desc); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -171,11 +195,14 @@ struct KeyPoints MSER_Detect(MSER a, Mat src) { (*a)->detect(*src, detected); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -194,11 +221,14 @@ struct KeyPoints FastFeatureDetector_Detect(FastFeatureDetector f, Mat src) { (*f)->detect(*src, detected); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -217,11 +247,14 @@ struct KeyPoints ORB_Detect(ORB o, Mat src) { (*o)->detect(*src, detected); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -231,11 +264,14 @@ struct KeyPoints ORB_DetectAndCompute(ORB o, Mat src, Mat mask, Mat desc) { (*o)->detectAndCompute(*src, *mask, detected, *desc); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } @@ -254,11 +290,14 @@ struct KeyPoints SimpleBlobDetector_Detect(SimpleBlobDetector b, Mat src) { (*b)->detect(*src, detected); KeyPoint* kps = new KeyPoint[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, - detected[i].response, detected[i].octave, detected[i].class_id}; - kps[i] = k; + KeyPoint k = {detected[i].pt.x, detected[i].pt.y, detected[i].size, detected[i].angle, + detected[i].response, detected[i].octave, detected[i].class_id + }; + kps[i] = k; } + KeyPoints ret = {kps, (int)detected.size()}; return ret; } diff --git a/highgui.cpp b/highgui.cpp index 73fd0f58..15aed5e6 100644 --- a/highgui.cpp +++ b/highgui.cpp @@ -47,12 +47,14 @@ struct Rects Window_SelectROIs(const char* winname, Mat img) { std::vector rois; cv::selectROIs(winname, *img, rois); Rect* rects = new Rect[rois.size()]; + for (size_t i = 0; i < rois.size(); ++i) { - Rect r = {rois[i].x, rois[i].y, rois[i].width, rois[i].height}; - rects[i] = r; + Rect r = {rois[i].x, rois[i].y, rois[i].width, rois[i].height}; + rects[i] = r; } + Rects ret = {rects, (int)rois.size()}; - return ret; + return ret; } // Trackbar diff --git a/imgcodecs.cpp b/imgcodecs.cpp index c02ce116..f392db4b 100644 --- a/imgcodecs.cpp +++ b/imgcodecs.cpp @@ -13,9 +13,11 @@ bool Image_IMWrite(const char* filename, Mat img) { bool Image_IMWrite_WithParams(const char* filename, Mat img, IntVector params) { std::vector compression_params; - for(int i = 0, *v = params.val; i < params.length; ++v, ++i) { + + for (int i = 0, *v = params.val; i < params.length; ++v, ++i) { compression_params.push_back(*v); } + return cv::imwrite(filename, *img, compression_params); } @@ -27,6 +29,7 @@ struct ByteArray Image_IMEncode(const char* fileExt, Mat img) { Mat Image_IMDecode(ByteArray buf, int flags) { std::vector data; + for (size_t i = 0; i < buf.length; i++) { data.push_back(buf.data[i]); } diff --git a/imgproc.cpp b/imgproc.cpp index 7b1dcdb7..9f61a169 100644 --- a/imgproc.cpp +++ b/imgproc.cpp @@ -2,14 +2,17 @@ double ArcLength(Contour curve, bool is_closed) { std::vector pts; + for (size_t i = 0; i < curve.length; i++) { pts.push_back(cv::Point(curve.points[i].x, curve.points[i].y)); } + return cv::arcLength(pts, is_closed); } Contour ApproxPolyDP(Contour curve, double epsilon, bool closed) { std::vector curvePts; + for (size_t i = 0; i < curve.length; i++) { curvePts.push_back(cv::Point(curve.points[i].x, curve.points[i].y)); } @@ -19,9 +22,11 @@ Contour ApproxPolyDP(Contour curve, double epsilon, bool closed) { int length = approxCurvePts.size(); Point* points = new Point[length]; + for (size_t i = 0; i < length; i++) { points[i] = Point{approxCurvePts[i].x, approxCurvePts[i].y}; } + return Contour{points, length}; } @@ -31,6 +36,7 @@ void CvtColor(Mat src, Mat dst, int code) { void ConvexHull(Contour points, Mat hull, bool clockwise, bool returnPoints) { std::vector pts; + for (size_t i = 0; i < points.length; i++) { pts.push_back(cv::Point(points.points[i].x, points.points[i].y)); } @@ -40,6 +46,7 @@ void ConvexHull(Contour points, Mat hull, bool clockwise, bool returnPoints) { void ConvexityDefects(Contour points, Mat hull, Mat result) { std::vector pts; + for (size_t i = 0; i < points.length; i++) { pts.push_back(cv::Point(points.points[i].x, points.points[i].y)); } @@ -71,8 +78,9 @@ void MatchTemplate(Mat image, Mat templ, Mat result, int method, Mat mask) { struct Moment Moments(Mat src, bool binaryImage) { cv::Moments m = cv::moments(*src, binaryImage); Moment mom = {m.m00, m.m10, m.m01, m.m20, m.m11, m.m02, m.m30, m.m21, m.m12, m.m03, - m.mu20, m.mu11, m.mu02, m.mu30, m.mu21, m.mu12, m.mu03, - m.nu20, m.nu11, m.nu02, m.nu30, m.nu21, m.nu12, m.nu03}; + m.mu20, m.mu11, m.mu02, m.mu30, m.mu21, m.mu12, m.mu03, + m.nu20, m.nu11, m.nu02, m.nu30, m.nu21, m.nu12, m.nu03 + }; return mom; } @@ -88,9 +96,11 @@ void PyrUp(Mat src, Mat dst, Size size, int borderType) { struct Rect BoundingRect(Contour con) { std::vector pts; + for (size_t i = 0; i < con.length; i++) { pts.push_back(cv::Point(con.points[i].x, con.points[i].y)); } + cv::Rect bRect = cv::boundingRect(pts); Rect r = {bRect.x, bRect.y, bRect.width, bRect.height}; return r; @@ -98,9 +108,11 @@ struct Rect BoundingRect(Contour con) { double ContourArea(Contour con) { std::vector pts; + for (size_t i = 0; i < con.length; i++) { pts.push_back(cv::Point(con.points[i].x, con.points[i].y)); } + return cv::contourArea(pts); } @@ -109,12 +121,15 @@ struct Contours FindContours(Mat src, int mode, int method) { cv::findContours(*src, contours, mode, method); Contour* points = new Contour[contours.size()]; + for (size_t i = 0; i < contours.size(); i++) { - Point *pts = new Point[contours[i].size()]; + Point* pts = new Point[contours[i].size()]; + for (size_t j = 0; j < contours[i].size(); j++) { Point pt = {contours[i][j].x, contours[i][j].y}; pts[j] = pt; } + points[i] = Contour{pts, (int)contours[i].size()}; } @@ -136,11 +151,13 @@ void GaussianBlur(Mat src, Mat dst, Size ps, double sX, double sY, int bt) { cv::GaussianBlur(*src, *dst, sz, sX, sY, bt); } -void Laplacian(Mat src, Mat dst, int dDepth, int kSize, double scale, double delta, int borderType) { +void Laplacian(Mat src, Mat dst, int dDepth, int kSize, double scale, double delta, + int borderType) { cv::Laplacian(*src, *dst, dDepth, kSize, scale, delta, borderType); } -void Scharr(Mat src, Mat dst, int dDepth, int dx, int dy, double scale, double delta, int borderType) { +void Scharr(Mat src, Mat dst, int dDepth, int dx, int dy, double scale, double delta, + int borderType) { cv::Scharr(*src, *dst, dDepth, dx, dy, scale, delta, borderType); } @@ -178,7 +195,8 @@ void Threshold(Mat src, Mat dst, double thresh, double maxvalue, int typ) { cv::threshold(*src, *dst, thresh, maxvalue, typ); } -void AdaptiveThreshold(Mat src, Mat dst, double maxValue, int adaptiveMethod, int thresholdType, int blockSize, double c) { +void AdaptiveThreshold(Mat src, Mat dst, double maxValue, int adaptiveMethod, int thresholdType, + int blockSize, double c) { cv::adaptiveThreshold(*src, *dst, maxValue, adaptiveMethod, thresholdType, blockSize, c); } @@ -207,8 +225,8 @@ void Line(Mat img, Point pt1, Point pt2, Scalar color, int thickness) { void Rectangle(Mat img, Rect r, Scalar color, int thickness) { cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); - cv::rectangle(*img, cv::Point(r.x, r.y), cv::Point(r.x+r.width, r.y+r.height), - c, thickness, CV_AA); + cv::rectangle(*img, cv::Point(r.x, r.y), cv::Point(r.x + r.width, r.y + r.height), + c, thickness, CV_AA); } struct Size GetTextSize(const char* text, int fontFace, double fontScale, int thickness) { @@ -218,72 +236,78 @@ struct Size GetTextSize(const char* text, int fontFace, double fontScale, int th } void PutText(Mat img, const char* text, Point org, int fontFace, double fontScale, - Scalar color, int thickness) { + Scalar color, int thickness) { cv::Point pt(org.x, org.y); cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); cv::putText(*img, text, pt, fontFace, fontScale, c, thickness); } void Resize(Mat src, Mat dst, Size dsize, double fx, double fy, int interp) { - cv::Size sz(dsize.width, dsize.height); - cv::resize(*src, *dst, sz, fx, fy, interp); + cv::Size sz(dsize.width, dsize.height); + cv::resize(*src, *dst, sz, fx, fy, interp); } Mat GetRotationMatrix2D(Point center, double angle, double scale) { - cv::Point pt(center.x, center.y); - return new cv::Mat(cv::getRotationMatrix2D( pt, angle, scale)); + cv::Point pt(center.x, center.y); + return new cv::Mat(cv::getRotationMatrix2D(pt, angle, scale)); } void WarpAffine(Mat src, Mat dst, Mat m, Size dsize) { - cv::Size sz(dsize.width, dsize.height); - cv::warpAffine(*src, *dst, *m, sz); + cv::Size sz(dsize.width, dsize.height); + cv::warpAffine(*src, *dst, *m, sz); } -void WarpAffineWithParams(Mat src, Mat dst, Mat rot_mat, Size dsize, int flags, int borderMode, Scalar borderValue) { - cv::Size sz(dsize.width, dsize.height); - cv::Scalar c = cv::Scalar(borderValue.val1, borderValue.val2, borderValue.val3, borderValue.val4); - cv::warpAffine(*src, *dst, *rot_mat, sz, flags, borderMode, c); +void WarpAffineWithParams(Mat src, Mat dst, Mat rot_mat, Size dsize, int flags, int borderMode, + Scalar borderValue) { + cv::Size sz(dsize.width, dsize.height); + cv::Scalar c = cv::Scalar(borderValue.val1, borderValue.val2, borderValue.val3, borderValue.val4); + cv::warpAffine(*src, *dst, *rot_mat, sz, flags, borderMode, c); } void WarpPerspective(Mat src, Mat dst, Mat m, Size dsize) { - cv::Size sz(dsize.width, dsize.height); - cv::warpPerspective(*src, *dst, *m, sz); + cv::Size sz(dsize.width, dsize.height); + cv::warpPerspective(*src, *dst, *m, sz); } void ApplyColorMap(Mat src, Mat dst, int colormap) { - cv::applyColorMap(*src, *dst, colormap); + cv::applyColorMap(*src, *dst, colormap); } void ApplyCustomColorMap(Mat src, Mat dst, Mat colormap) { - cv::applyColorMap(*src, *dst, *colormap); + cv::applyColorMap(*src, *dst, *colormap); } Mat GetPerspectiveTransform(Contour src, Contour dst) { - std::vector src_pts; - for (size_t i = 0; i < src.length; i++) { - src_pts.push_back(cv::Point2f(src.points[i].x, src.points[i].y)); - } - std::vector dst_pts; - for (size_t i = 0; i < dst.length; i++) { - dst_pts.push_back(cv::Point2f(dst.points[i].x, dst.points[i].y)); - } + std::vector src_pts; + + for (size_t i = 0; i < src.length; i++) { + src_pts.push_back(cv::Point2f(src.points[i].x, src.points[i].y)); + } + + std::vector dst_pts; + + for (size_t i = 0; i < dst.length; i++) { + dst_pts.push_back(cv::Point2f(dst.points[i].x, dst.points[i].y)); + } - return new cv::Mat(cv::getPerspectiveTransform(src_pts, dst_pts)); + return new cv::Mat(cv::getPerspectiveTransform(src_pts, dst_pts)); } void DrawContours(Mat src, Contours contours, int contourIdx, Scalar color, int thickness) { - std::vector > cntrs; - for (size_t i = 0; i < contours.length; i++) { - Contour contour = contours.contours[i]; + std::vector > cntrs; - std::vector cntr; - for (size_t i = 0; i < contour.length; i++) { - cntr.push_back(cv::Point(contour.points[i].x, contour.points[i].y)); - } + for (size_t i = 0; i < contours.length; i++) { + Contour contour = contours.contours[i]; + + std::vector cntr; + + for (size_t i = 0; i < contour.length; i++) { + cntr.push_back(cv::Point(contour.points[i].x, contour.points[i].y)); + } - cntrs.push_back(cntr); - } + cntrs.push_back(cntr); + } - cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); - cv::drawContours(*src, cntrs, contourIdx, c, thickness); + cv::Scalar c = cv::Scalar(color.val1, color.val2, color.val3, color.val4); + cv::drawContours(*src, cntrs, contourIdx, c, thickness); } diff --git a/imgproc.h b/imgproc.h index 32f85241..f51d5a82 100644 --- a/imgproc.h +++ b/imgproc.h @@ -28,7 +28,8 @@ double ContourArea(Contour con); struct Contours FindContours(Mat src, int mode, int method); void GaussianBlur(Mat src, Mat dst, Size ps, double sX, double sY, int bt); void Laplacian(Mat src, Mat dst, int dDepth, int kSize, double scale, double delta, int borderType); -void Scharr(Mat src, Mat dst, int dDepth, int dx, int dy, double scale, double delta, int borderType); +void Scharr(Mat src, Mat dst, int dDepth, int dx, int dy, double scale, double delta, + int borderType); Mat GetStructuringElement(int shape, Size ksize); void MorphologyEx(Mat src, Mat dst, int op, Mat kernel); void MedianBlur(Mat src, Mat dst, int ksize); @@ -40,7 +41,8 @@ void HoughCircles(Mat src, Mat circles, int method, double dp, double minDist); void HoughLines(Mat src, Mat lines, double rho, double theta, int threshold); void HoughLinesP(Mat src, Mat lines, double rho, double theta, int threshold); void Threshold(Mat src, Mat dst, double thresh, double maxvalue, int typ); -void AdaptiveThreshold(Mat src, Mat dst, double maxValue, int adaptiveTyp, int typ, int blockSize, double c); +void AdaptiveThreshold(Mat src, Mat dst, double maxValue, int adaptiveTyp, int typ, int blockSize, + double c); void ArrowedLine(Mat img, Point pt1, Point pt2, Scalar color, int thickness); void Circle(Mat img, Point center, int radius, Scalar color, int thickness); @@ -52,7 +54,8 @@ void PutText(Mat img, const char* text, Point org, int fontFace, double fontScal void Resize(Mat src, Mat dst, Size sz, double fx, double fy, int interp); Mat GetRotationMatrix2D(Point center, double angle, double scale); void WarpAffine(Mat src, Mat dst, Mat rot_mat, Size dsize); -void WarpAffineWithParams(Mat src, Mat dst, Mat rot_mat, Size dsize, int flags, int borderMode, Scalar borderValue); +void WarpAffineWithParams(Mat src, Mat dst, Mat rot_mat, Size dsize, int flags, int borderMode, + Scalar borderValue); void WarpPerspective(Mat src, Mat dst, Mat m, Size dsize); void ApplyColorMap(Mat src, Mat dst, int colormap); void ApplyCustomColorMap(Mat src, Mat dst, Mat colormap); diff --git a/objdetect.cpp b/objdetect.cpp index 38e66beb..e3bb4e77 100644 --- a/objdetect.cpp +++ b/objdetect.cpp @@ -5,29 +5,31 @@ CascadeClassifier CascadeClassifier_New() { return new cv::CascadeClassifier(); } - + void CascadeClassifier_Close(CascadeClassifier cs) { delete cs; } - + int CascadeClassifier_Load(CascadeClassifier cs, const char* name) { return cs->load(name); } - + struct Rects CascadeClassifier_DetectMultiScale(CascadeClassifier cs, Mat img) { std::vector detected; cs->detectMultiScale(*img, detected); // uses all default parameters Rect* rects = new Rect[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height}; - rects[i] = r; + Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height}; + rects[i] = r; } + Rects ret = {rects, (int)detected.size()}; return ret; } struct Rects CascadeClassifier_DetectMultiScaleWithParams(CascadeClassifier cs, Mat img, - double scale, int minNeighbors, int flags, Size minSize, Size maxSize) { + double scale, int minNeighbors, int flags, Size minSize, Size maxSize) { cv::Size minSz(minSize.width, minSize.height); cv::Size maxSz(maxSize.width, maxSize.height); @@ -35,10 +37,12 @@ struct Rects CascadeClassifier_DetectMultiScaleWithParams(CascadeClassifier cs, std::vector detected; cs->detectMultiScale(*img, detected, scale, minNeighbors, flags, minSz, maxSz); Rect* rects = new Rect[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height}; - rects[i] = r; + Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height}; + rects[i] = r; } + Rects ret = {rects, (int)detected.size()}; return ret; } @@ -61,28 +65,33 @@ struct Rects HOGDescriptor_DetectMultiScale(HOGDescriptor hog, Mat img) { std::vector detected; hog->detectMultiScale(*img, detected); Rect* rects = new Rect[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height}; - rects[i] = r; + Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height}; + rects[i] = r; } + Rects ret = {rects, (int)detected.size()}; return ret; } struct Rects HOGDescriptor_DetectMultiScaleWithParams(HOGDescriptor hog, Mat img, - double hitThresh, Size winStride, Size padding, double scale, double finalThresh, - bool useMeanshiftGrouping) { + double hitThresh, Size winStride, Size padding, double scale, double finalThresh, + bool useMeanshiftGrouping) { cv::Size wSz(winStride.width, winStride.height); cv::Size pSz(padding.width, padding.height); std::vector detected; - hog->detectMultiScale(*img, detected, hitThresh, wSz, pSz, scale, finalThresh, useMeanshiftGrouping); + hog->detectMultiScale(*img, detected, hitThresh, wSz, pSz, scale, finalThresh, + useMeanshiftGrouping); Rect* rects = new Rect[detected.size()]; + for (size_t i = 0; i < detected.size(); ++i) { - Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height}; - rects[i] = r; + Rect r = {detected[i].x, detected[i].y, detected[i].width, detected[i].height}; + rects[i] = r; } + Rects ret = {rects, (int)detected.size()}; return ret; } @@ -97,18 +106,22 @@ void HOGDescriptor_SetSVMDetector(HOGDescriptor hog, Mat det) { struct Rects GroupRectangles(struct Rects rects, int groupThreshold, double eps) { std::vector vRect; + for (int i = 0; i < rects.length; ++i) { - cv::Rect r = cv::Rect(rects.rects[i].x, rects.rects[i].y, rects.rects[i].width, rects.rects[i].height); + cv::Rect r = cv::Rect(rects.rects[i].x, rects.rects[i].y, rects.rects[i].width, + rects.rects[i].height); vRect.push_back(r); } cv::groupRectangles(vRect, groupThreshold, eps); Rect* results = new Rect[vRect.size()]; + for (size_t i = 0; i < vRect.size(); ++i) { - Rect r = {vRect[i].x, vRect[i].y, vRect[i].width, vRect[i].height}; - results[i] = r; + Rect r = {vRect[i].x, vRect[i].y, vRect[i].width, vRect[i].height}; + results[i] = r; } + Rects ret = {results, (int)vRect.size()}; return ret; } diff --git a/objdetect.h b/objdetect.h index 61a9432f..362510f4 100644 --- a/objdetect.h +++ b/objdetect.h @@ -24,14 +24,15 @@ void CascadeClassifier_Close(CascadeClassifier cs); int CascadeClassifier_Load(CascadeClassifier cs, const char* name); struct Rects CascadeClassifier_DetectMultiScale(CascadeClassifier cs, Mat img); struct Rects CascadeClassifier_DetectMultiScaleWithParams(CascadeClassifier cs, Mat img, - double scale, int minNeighbors, int flags, Size minSize, Size maxSize); + double scale, int minNeighbors, int flags, Size minSize, Size maxSize); HOGDescriptor HOGDescriptor_New(); void HOGDescriptor_Close(HOGDescriptor hog); int HOGDescriptor_Load(HOGDescriptor hog, const char* name); struct Rects HOGDescriptor_DetectMultiScale(HOGDescriptor hog, Mat img); struct Rects HOGDescriptor_DetectMultiScaleWithParams(HOGDescriptor hog, Mat img, - double hitThresh, Size winStride, Size padding, double scale, double finalThreshold, bool useMeanshiftGrouping); + double hitThresh, Size winStride, Size padding, double scale, double finalThreshold, + bool useMeanshiftGrouping); Mat HOG_GetDefaultPeopleDetector(); void HOGDescriptor_SetSVMDetector(HOGDescriptor hog, Mat det); diff --git a/pvl/face.cpp b/pvl/face.cpp index 3566e1df..b9cf6777 100644 --- a/pvl/face.cpp +++ b/pvl/face.cpp @@ -1,19 +1,16 @@ #include "face.h" // Face -Face Face_New() -{ +Face Face_New() { return new cv::pvl::Face(); } -void Face_Close(Face face) -{ +void Face_Close(Face face) { delete face; } // Face_CopyTo only copies the Face Rect data. -void Face_CopyTo(Face src, Face dst) -{ +void Face_CopyTo(Face src, Face dst) { cv::Rect faceRect = src->get(cv::pvl::Face::FACE_RECT); int ripAngle = src->get(cv::pvl::Face::RIP_ANGLE); int ropAngle = src->get(cv::pvl::Face::ROP_ANGLE); @@ -22,56 +19,47 @@ void Face_CopyTo(Face src, Face dst) dst->setFaceRectInfo(faceRect, ripAngle, ropAngle, confidence, trackingID); } -Rect Face_GetRect(Face face) -{ +Rect Face_GetRect(Face face) { cv::Rect faceRect = face->get(cv::pvl::Face::FACE_RECT); Rect r = {faceRect.x, faceRect.y, faceRect.width, faceRect.height}; return r; } -int Face_RIPAngle(Face face) -{ +int Face_RIPAngle(Face face) { return face->get(cv::pvl::Face::RIP_ANGLE); } -int Face_ROPAngle(Face face) -{ +int Face_ROPAngle(Face face) { return face->get(cv::pvl::Face::ROP_ANGLE); } -Point Face_LeftEyePosition(Face face) -{ +Point Face_LeftEyePosition(Face face) { cv::Point pt = face->get(cv::pvl::Face::LEFT_EYE_POS); Point p = {pt.x, pt.y}; return p; } -bool Face_LeftEyeClosed(Face face) -{ +bool Face_LeftEyeClosed(Face face) { return face->get(cv::pvl::Face::CLOSING_LEFT_EYE); } -Point Face_RightEyePosition(Face face) -{ +Point Face_RightEyePosition(Face face) { cv::Point pt = face->get(cv::pvl::Face::RIGHT_EYE_POS); Point p = {pt.x, pt.y}; return p; } -bool Face_RightEyeClosed(Face face) -{ +bool Face_RightEyeClosed(Face face) { return face->get(cv::pvl::Face::CLOSING_RIGHT_EYE); } -Point Face_MouthPosition(Face face) -{ +Point Face_MouthPosition(Face face) { cv::Point pt = face->get(cv::pvl::Face::MOUTH_POS); Point p = {pt.x, pt.y}; return p; } -bool Face_IsSmiling(Face face) -{ +bool Face_IsSmiling(Face face) { return face->get(cv::pvl::Face::SMILING); } diff --git a/pvl/face_detector.cpp b/pvl/face_detector.cpp index 9440a217..6fa748f1 100644 --- a/pvl/face_detector.cpp +++ b/pvl/face_detector.cpp @@ -1,13 +1,11 @@ #include "face_detector.h" // FaceDetector -FaceDetector FaceDetector_New() -{ +FaceDetector FaceDetector_New() { return new cv::Ptr(cv::pvl::FaceDetector::create()); } -void FaceDetector_Close(FaceDetector f) -{ +void FaceDetector_Close(FaceDetector f) { delete f; } @@ -59,8 +57,7 @@ void FaceDetector_SetSmileThreshold(FaceDetector f, int thresh) { (*f)->setSmileThreshold(thresh); } -void FaceDetector_SetTrackingModeEnabled(FaceDetector f, bool enabled) -{ +void FaceDetector_SetTrackingModeEnabled(FaceDetector f, bool enabled) { (*f)->setTrackingModeEnabled(enabled); return; } @@ -69,42 +66,39 @@ bool FaceDetector_IsTrackingModeEnabled(FaceDetector f) { return (*f)->isTrackingModeEnabled(); } -struct Faces FaceDetector_DetectFaceRect(FaceDetector fd, Mat img) -{ +struct Faces FaceDetector_DetectFaceRect(FaceDetector fd, Mat img) { std::vector faces; (*fd)->detectFaceRect(*img, faces); Face* fs = new Face[faces.size()]; + for (size_t i = 0; i < faces.size(); ++i) { Face f = Face_New(); Face_CopyTo(&faces[i], f); fs[i] = f; } + Faces ret = {fs, (int)faces.size()}; return ret; } -void FaceDetector_DetectEye(FaceDetector f, Mat img, Face face) -{ +void FaceDetector_DetectEye(FaceDetector f, Mat img, Face face) { (*f)->detectEye(*img, *face); return; } -void FaceDetector_DetectMouth(FaceDetector f, Mat img, Face face) -{ +void FaceDetector_DetectMouth(FaceDetector f, Mat img, Face face) { (*f)->detectMouth(*img, *face); return; } -void FaceDetector_DetectSmile(FaceDetector f, Mat img, Face face) -{ +void FaceDetector_DetectSmile(FaceDetector f, Mat img, Face face) { (*f)->detectSmile(*img, *face); return; } -void FaceDetector_DetectBlink(FaceDetector f, Mat img, Face face) -{ +void FaceDetector_DetectBlink(FaceDetector f, Mat img, Face face) { (*f)->detectBlink(*img, *face); return; } diff --git a/pvl/face_recognizer.cpp b/pvl/face_recognizer.cpp index abbcacf9..5e23130c 100644 --- a/pvl/face_recognizer.cpp +++ b/pvl/face_recognizer.cpp @@ -1,13 +1,11 @@ #include "face_recognizer.h" // FaceRecognizer -FaceRecognizer FaceRecognizer_New() -{ +FaceRecognizer FaceRecognizer_New() { return new cv::Ptr(cv::pvl::FaceRecognizer::create()); } -void FaceRecognizer_Close(FaceRecognizer f) -{ +void FaceRecognizer_Close(FaceRecognizer f) { delete f; } @@ -19,8 +17,7 @@ bool FaceRecognizer_Empty(FaceRecognizer f) { return (*f)->empty(); } -void FaceRecognizer_SetTrackingModeEnabled(FaceRecognizer f, bool enabled) -{ +void FaceRecognizer_SetTrackingModeEnabled(FaceRecognizer f, bool enabled) { (*f)->setTrackingModeEnabled(enabled); return; } @@ -33,8 +30,10 @@ int FaceRecognizer_CreateNewPersonID(FaceRecognizer f) { return (*f)->createNewPersonID(); } -void FaceRecognizer_Recognize(FaceRecognizer f, Mat img, Faces faces, IntVector* pids, IntVector* confs) { +void FaceRecognizer_Recognize(FaceRecognizer f, Mat img, Faces faces, IntVector* pids, + IntVector* confs) { std::vector vFaces; + for (size_t i = 0; i < faces.length; ++i) { vFaces.push_back(cv::pvl::Face(*faces.faces[i])); } @@ -45,7 +44,8 @@ void FaceRecognizer_Recognize(FaceRecognizer f, Mat img, Faces faces, IntVector* (*f)->recognize(*img, vFaces, personIDs, confidence); int* aInt = new int[personIDs.size()]; - for(int i = 0; i < personIDs.size(); ++i) { + + for (int i = 0; i < personIDs.size(); ++i) { aInt[i] = personIDs[i]; } @@ -53,7 +53,8 @@ void FaceRecognizer_Recognize(FaceRecognizer f, Mat img, Faces faces, IntVector* pids->length = personIDs.size(); int* aConf = new int[confidence.size()]; - for(int i = 0; i < confidence.size(); ++i) { + + for (int i = 0; i < confidence.size(); ++i) { aConf[i] = confidence[i]; } @@ -63,7 +64,8 @@ void FaceRecognizer_Recognize(FaceRecognizer f, Mat img, Faces faces, IntVector* return; } -int64_t FaceRecognizer_RegisterFace(FaceRecognizer f, Mat img, Face face, int personID, bool saveTofile) { +int64_t FaceRecognizer_RegisterFace(FaceRecognizer f, Mat img, Face face, int personID, + bool saveTofile) { return (*f)->registerFace(*img, cv::pvl::Face(*face), personID, saveTofile); } diff --git a/pvl/face_recognizer.h b/pvl/face_recognizer.h index b1ae852f..5a2cc463 100644 --- a/pvl/face_recognizer.h +++ b/pvl/face_recognizer.h @@ -24,8 +24,10 @@ bool FaceRecognizer_Empty(FaceRecognizer f); void FaceRecognizer_SetTrackingModeEnabled(FaceRecognizer f, bool enabled); int FaceRecognizer_CreateNewPersonID(FaceRecognizer f); int FaceRecognizer_GetNumRegisteredPersons(FaceRecognizer f); -void FaceRecognizer_Recognize(FaceRecognizer f, Mat img, Faces faces, IntVector* pids, IntVector* confs); -int64_t FaceRecognizer_RegisterFace(FaceRecognizer f, Mat img, Face face, int personID, bool saveTofile); +void FaceRecognizer_Recognize(FaceRecognizer f, Mat img, Faces faces, IntVector* pids, + IntVector* confs); +int64_t FaceRecognizer_RegisterFace(FaceRecognizer f, Mat img, Face face, int personID, + bool saveTofile); void FaceRecognizer_DeregisterFace(FaceRecognizer f, int64_t faceID); void FaceRecognizer_DeregisterPerson(FaceRecognizer f, int personID); FaceRecognizer FaceRecognizer_Load(const char* filename); diff --git a/version.cpp b/version.cpp index b8b4baaa..d4aa1654 100644 --- a/version.cpp +++ b/version.cpp @@ -1,5 +1,5 @@ #include "version.h" -const char *openCVVersion() { +const char* openCVVersion() { return CV_VERSION; } diff --git a/version.h b/version.h index 8f00291a..3372e577 100644 --- a/version.h +++ b/version.h @@ -8,7 +8,7 @@ extern "C" { #include "core.h" -const char *openCVVersion(); +const char* openCVVersion(); #ifdef __cplusplus } diff --git a/video.cpp b/video.cpp index be72e0ee..2b2c6252 100644 --- a/video.cpp +++ b/video.cpp @@ -24,9 +24,10 @@ void BackgroundSubtractorKNN_Apply(BackgroundSubtractorKNN k, Mat src, Mat dst) (*k)->apply(*src, *dst); } -void CalcOpticalFlowFarneback(Mat prevImg, Mat nextImg, Mat flow, double scale, int levels, int winsize, - int iterations, int polyN, double polySigma, int flags) { - cv::calcOpticalFlowFarneback(*prevImg, *nextImg, *flow, scale, levels, winsize, iterations, polyN, polySigma, flags); +void CalcOpticalFlowFarneback(Mat prevImg, Mat nextImg, Mat flow, double scale, int levels, + int winsize, int iterations, int polyN, double polySigma, int flags) { + cv::calcOpticalFlowFarneback(*prevImg, *nextImg, *flow, scale, levels, winsize, iterations, polyN, + polySigma, flags); } void CalcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, Mat prevPts, Mat nextPts, Mat status, Mat err) { diff --git a/video.h b/video.h index 22b1e728..93f6d955 100644 --- a/video.h +++ b/video.h @@ -25,8 +25,8 @@ void BackgroundSubtractorKNN_Close(BackgroundSubtractorKNN b); void BackgroundSubtractorKNN_Apply(BackgroundSubtractorKNN b, Mat src, Mat dst); void CalcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, Mat prevPts, Mat nextPts, Mat status, Mat err); -void CalcOpticalFlowFarneback(Mat prevImg, Mat nextImg, Mat flow, double pyrScale, int levels, int winsize, - int iterations, int polyN, double polySigma, int flags); +void CalcOpticalFlowFarneback(Mat prevImg, Mat nextImg, Mat flow, double pyrScale, int levels, + int winsize, int iterations, int polyN, double polySigma, int flags); #ifdef __cplusplus } #endif diff --git a/videoio.cpp b/videoio.cpp index d0de64df..ed513eff 100644 --- a/videoio.cpp +++ b/videoio.cpp @@ -22,7 +22,7 @@ void VideoCapture_Set(VideoCapture v, int prop, double param) { } double VideoCapture_Get(VideoCapture v, int prop) { - return v->get(prop); + return v->get(prop); } int VideoCapture_IsOpened(VideoCapture v) { @@ -34,7 +34,7 @@ int VideoCapture_Read(VideoCapture v, Mat buf) { } void VideoCapture_Grab(VideoCapture v, int skip) { - for (int i =0; i < skip; i++) { + for (int i = 0; i < skip; i++) { v->grab(); } } @@ -49,7 +49,7 @@ void VideoWriter_Close(VideoWriter vw) { } void VideoWriter_Open(VideoWriter vw, const char* name, const char* codec, double fps, int width, - int height) { + int height) { int codecCode = cv::VideoWriter::fourcc(codec[0], codec[1], codec[2], codec[3]); vw->open(name, codecCode, fps, cv::Size(width, height), true); } diff --git a/videoio.h b/videoio.h index 17809598..6b90adc2 100644 --- a/videoio.h +++ b/videoio.h @@ -31,7 +31,7 @@ void VideoCapture_Grab(VideoCapture v, int skip); VideoWriter VideoWriter_New(); void VideoWriter_Close(VideoWriter vw); void VideoWriter_Open(VideoWriter vw, const char* name, const char* codec, double fps, int width, - int height); + int height); int VideoWriter_IsOpened(VideoWriter vw); void VideoWriter_Write(VideoWriter vw, Mat img);