From e607a85df61581db88202a40f69f646d7237c9d6 Mon Sep 17 00:00:00 2001 From: Ishank gulati Date: Wed, 23 Dec 2015 23:37:32 +0530 Subject: [PATCH 01/30] png-image-compatibility --- modules/videoio/src/cap_images.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/videoio/src/cap_images.cpp b/modules/videoio/src/cap_images.cpp index 00d5af47d1..e379561593 100644 --- a/modules/videoio/src/cap_images.cpp +++ b/modules/videoio/src/cap_images.cpp @@ -124,7 +124,7 @@ bool CvCapture_Images::grabFrame() } cvReleaseImage(&frame); - frame = cvLoadImage(str, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR); + frame = cvLoadImage(str, CV_LOAD_IMAGE_UNCHANGED); if( frame ) currentframe++; From 7f52a553d47172eef1ebf7d0211bf3d6ebb92714 Mon Sep 17 00:00:00 2001 From: debjan Date: Mon, 30 May 2016 10:47:59 +0200 Subject: [PATCH 02/30] Update gen_pattern.py Save method should save, instead trying to run inkview --- doc/pattern_tools/gen_pattern.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/pattern_tools/gen_pattern.py b/doc/pattern_tools/gen_pattern.py index ebeeb123fe..85b3ea4955 100755 --- a/doc/pattern_tools/gen_pattern.py +++ b/doc/pattern_tools/gen_pattern.py @@ -61,7 +61,7 @@ class PatternMaker: def save(self): c = canvas(self.g,width="%d%s"%(self.width,self.units),height="%d%s"%(self.height,self.units),viewBox="0 0 %d %d"%(self.width,self.height)) - c.inkview(self.output) + c.save(self.output) def main(): From c03d778ec7c9e84eaae0dfccf7e7fdbaeaf1181e Mon Sep 17 00:00:00 2001 From: Louis Letourneau Date: Thu, 19 May 2016 09:29:28 -0400 Subject: [PATCH 03/30] This fixes the seeking in h264 B-Frame enabled video issue. #4890 --- modules/videoio/src/cap_ffmpeg_impl.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/videoio/src/cap_ffmpeg_impl.hpp b/modules/videoio/src/cap_ffmpeg_impl.hpp index 8ac33d749d..4a725bc20b 100644 --- a/modules/videoio/src/cap_ffmpeg_impl.hpp +++ b/modules/videoio/src/cap_ffmpeg_impl.hpp @@ -971,7 +971,8 @@ bool CvCapture_FFMPEG::grabFrame() { //picture_pts = picture->best_effort_timestamp; if( picture_pts == AV_NOPTS_VALUE_ ) - picture_pts = packet.pts != AV_NOPTS_VALUE_ && packet.pts != 0 ? packet.pts : packet.dts; + picture_pts = picture->pkt_pts != AV_NOPTS_VALUE_ && picture->pkt_pts != 0 ? picture->pkt_pts : picture->pkt_dts; + frame_number++; valid = true; } From ecd827fc8ea248ed3ebbb6e7e48f1b75e11fbd05 Mon Sep 17 00:00:00 2001 From: MYLS Date: Sat, 18 Jun 2016 21:40:29 +0800 Subject: [PATCH 04/30] Add Base64 support for FileStorage [GSoC] FileStorage: Add base64 support for reading and writting XML\YML file. The two new functions: ``` void cvWriteRawData_Base64(cv::FileStorage & fs, const void* _data, int len, const char* dt); void cvWriteMat_Base64(cv::FileStorage & fs, cv::String const & name, cv::Mat const & mat); ``` --- .../core/include/opencv2/core/persistence.hpp | 7 +- modules/core/src/persistence.cpp | 1354 ++++++++++++++++- modules/core/test/test_io.cpp | 121 ++ 3 files changed, 1472 insertions(+), 10 deletions(-) diff --git a/modules/core/include/opencv2/core/persistence.hpp b/modules/core/include/opencv2/core/persistence.hpp index 15454165ad..23714868bd 100644 --- a/modules/core/include/opencv2/core/persistence.hpp +++ b/modules/core/include/opencv2/core/persistence.hpp @@ -1238,6 +1238,11 @@ inline String::String(const FileNode& fn): cstr_(0), len_(0) { read(fn, *this, * //! @endcond + +CV_EXPORTS void cvWriteRawData_Base64(::cv::FileStorage & fs, const void* _data, int len, const char* dt); + +CV_EXPORTS void cvWriteMat_Base64(::cv::FileStorage & fs, ::cv::String const & name, ::cv::Mat const & mat); + } // cv -#endif // __OPENCV_CORE_PERSISTENCE_HPP__ +#endif // __OPENCV_CORE_PERSISTENCE_HPP__ \ No newline at end of file diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index 8f9a42abe6..4f323984bf 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -44,6 +44,8 @@ #include #include +#include +#include #include #define USE_ZLIB 1 @@ -242,6 +244,87 @@ typedef struct CvFileStorage } CvFileStorage; +namespace base64 +{ + static const size_t HEADER_SIZE = 24U; + static const size_t ENCODED_HEADER_SIZE = 32U; + + /* base64 */ + + typedef uchar uint8_t; + + extern uint8_t const base64_padding; + extern uint8_t const base64_mapping[65]; + extern uint8_t const base64_demapping[127]; + + size_t base64_encode(uint8_t const * src, uint8_t * dst, size_t off, size_t cnt); + size_t base64_encode( char const * src, char * dst, size_t off = 0U, size_t cnt = 0U); + + size_t base64_decode(uint8_t const * src, uint8_t * dst, size_t off, size_t cnt); + size_t base64_decode( char const * src, char * dst, size_t off = 0U, size_t cnt = 0U); + + bool base64_valid (uint8_t const * src, size_t off, size_t cnt); + bool base64_valid ( char const * src, size_t off = 0U, size_t cnt = 0U); + + size_t base64_encode_buffer_size(size_t cnt); + + size_t base64_decode_buffer_size(size_t cnt); + + /* binary */ + + template inline size_t to_binary(_uint_t val, uchar * cur); + template<> inline size_t to_binary(double val, uchar * cur); + template<> inline size_t to_binary(float val, uchar * cur); + template inline size_t to_binary(uchar const * val, uchar * cur); + + template inline size_t binary_to(uchar const * cur, _uint_t & val); + template<> inline size_t binary_to(uchar const * cur, double & val); + template<> inline size_t binary_to(uchar const * cur, float & val); + template inline size_t binary_to(uchar const * cur, uchar * val); + + class MatToBinaryConvertor; + class RawDataToBinaryConvertor; + + class BinaryToCvSeqConvertor; + + /* class */ + + class Base64ContextParser + { + public: + explicit Base64ContextParser(uchar * buffer, size_t size); + ~Base64ContextParser(); + Base64ContextParser & read(const uchar * beg, const uchar * end); + bool flush(); + private: + static const size_t BUFFER_LEN = 120U; + uchar * dst_cur; + uchar * dst_end; + uchar * dst_beg; + std::vector base64_buffer; + uchar * src_beg; + uchar * src_end; + uchar * src_cur; + std::vector binary_buffer; + }; + + class Base64ContextEmitter; + + /* other */ + + std::string make_base64_header(int byte_size, const char * dt); + + bool read_base64_header(std::string const & header, int & byte_size, std::string & dt); + + void make_seq(void * binary_data, int elem_cnt, const char * dt, CvSeq & seq); + + /* sample */ + + void cvWriteRawData_Base64(::cv::FileStorage & fs, const void* _data, int len, const char* dt); + void cvWriteMat_Base64(::cv::FileStorage & fs, ::cv::String const & name, ::cv::Mat const & mat); +} + + static void icvPuts( CvFileStorage* fs, const char* str ) { if( fs->outbuf ) @@ -995,6 +1078,95 @@ icvYMLSkipSpaces( CvFileStorage* fs, char* ptr, int min_indent, int max_comment_ } +static void icvYMLGetMultilineStringContent(CvFileStorage* fs, + char* ptr, int indent, char* &beg, char* &end) +{ + ptr = icvYMLSkipSpaces(fs, ptr, 0, INT_MAX); + beg = ptr; + end = ptr; + if (fs->dummy_eof) + return ; /* end of file */ + + if (ptr - fs->buffer_start != indent) + return ; /* end of string */ + + /* find end */ + while(cv_isprint(*ptr)) /* no check for base64 string */ + ++ ptr; + if (*ptr == '\0') + CV_PARSE_ERROR("Unexpected end of line"); + + end = ptr; +} + +static int icvCalcStructSize( const char* dt, int initial_size ); + +static char* icvYMLParseBase64(CvFileStorage* fs, char* ptr, int indent, CvFileNode * node) +{ + char * beg = 0; + char * end = 0; + + icvYMLGetMultilineStringContent(fs, ptr, indent, beg, end); + if (beg >= end) + return end; // CV_PARSE_ERROR("Empty Binary Data"); + + /* calc (decoded) total_byte_size from header */ + std::string dt; + int total_byte_size = -1; + { + if (end - beg < base64::ENCODED_HEADER_SIZE) + CV_PARSE_ERROR("Unrecognized Base64 header"); + + std::vector header(base64::HEADER_SIZE + 1, ' '); + base64::base64_decode(beg, header.data(), 0U, base64::ENCODED_HEADER_SIZE); + std::istringstream iss(header.data()); + + if (!(iss >> total_byte_size) || total_byte_size < 0) + CV_PARSE_ERROR("Cannot parse size in Base64 header"); + if (!(iss >> dt) || dt.empty()) + CV_PARSE_ERROR("Cannot parse dt in Base64 header"); + + beg += base64::ENCODED_HEADER_SIZE; + } + + /* buffer for decoded data(exclude header) */ + std::vector buffer(total_byte_size + 4); + { + base64::Base64ContextParser parser(buffer.data(), total_byte_size + 4); + + /* decoding */ + while(beg < end) + { + /* save this part [beg, end) */ + parser.read((const uchar *)beg, (const uchar *)end); + + beg = end; + + /* find next part */ + icvYMLGetMultilineStringContent(fs, beg, indent, beg, end); + } + } + /* save as CvSeq */ + int elem_size = ::icvCalcStructSize(dt.c_str(), 0); + if (total_byte_size % elem_size != 0) + CV_PARSE_ERROR("Byte size not match elememt size"); + int elem_cnt = total_byte_size / elem_size; + + node->tag = CV_NODE_NONE; + int struct_flags = CV_NODE_FLOW + CV_NODE_SEQ; /* after icvFSCreateCollection, node->tag == struct_flags */ + icvFSCreateCollection(fs, struct_flags, node); + base64::make_seq(buffer.data(), elem_cnt, dt.c_str(), *node->data.seq); + + if (fs->dummy_eof) { + /* end of file */ + return fs->buffer_start; + } else { + /* end of line */ + return end; + } +} + + static char* icvYMLParseKey( CvFileStorage* fs, char* ptr, CvFileNode* map_node, CvFileNode** value_placeholder ) @@ -1038,6 +1210,7 @@ icvYMLParseValue( CvFileStorage* fs, char* ptr, CvFileNode* node, int is_parent_flow = CV_NODE_IS_FLOW(parent_flags); int value_type = CV_NODE_NONE; int len; + bool is_binary_string = false; memset( node, 0, sizeof(*node) ); @@ -1074,6 +1247,27 @@ icvYMLParseValue( CvFileStorage* fs, char* ptr, CvFileNode* node, if( memcmp( ptr, "float", 5 ) == 0 ) value_type = CV_NODE_REAL; } + else if (len == 6 && CV_NODE_IS_USER(value_type)) + { + if( memcmp( ptr, "binary", 6 ) == 0 ) { + value_type = CV_NODE_SEQ; + is_binary_string = true; + + /* for ignore '|' */ + + /**** operation with endptr ****/ + *endptr = d; + + do { + d = *++endptr; + if (d == '|') + break; + } while (d == ' '); + + d = *++endptr; + *endptr = '\0'; + } + } else if( CV_NODE_IS_USER(value_type) ) { node->info = cvFindType( ptr ); @@ -1088,7 +1282,7 @@ icvYMLParseValue( CvFileStorage* fs, char* ptr, CvFileNode* node, if( !CV_NODE_IS_USER(value_type) ) { - if( value_type == CV_NODE_STRING && c != '\'' && c != '\"' ) + if (value_type == CV_NODE_STRING && c != '\'' && c != '\"') goto force_string; if( value_type == CV_NODE_INT ) goto force_int; @@ -1097,7 +1291,13 @@ icvYMLParseValue( CvFileStorage* fs, char* ptr, CvFileNode* node, } } - if( cv_isdigit(c) || + if (is_binary_string) + { + /* for base64 string */ + int indent = ptr - fs->buffer_start; + ptr = icvYMLParseBase64(fs, ptr, indent, node); + } + else if( cv_isdigit(c) || ((c == '-' || c == '+') && (cv_isdigit(d) || d == '.')) || (c == '.' && cv_isalnum(d))) // a number { @@ -1355,8 +1555,9 @@ icvYMLParse( CvFileStorage* fs ) if( *ptr == '%' ) { - if( memcmp( ptr, "%YAML:", 6 ) == 0 && - memcmp( ptr, "%YAML:1.", 8 ) != 0 ) + if( memcmp( ptr, "%YAML", 5 ) == 0 && + memcmp( ptr, "%YAML:1.", 8 ) != 0 && + memcmp( ptr, "%YAML 1.", 8 ) != 0) CV_PARSE_ERROR( "Unsupported YAML version (it must be 1.x)" ); *ptr = '\0'; } @@ -1521,7 +1722,14 @@ icvYMLStartWriteStruct( CvFileStorage* fs, const char* key, int struct_flags, CV_Error( CV_StsBadArg, "Some collection type - CV_NODE_SEQ or CV_NODE_MAP, must be specified" ); - if( CV_NODE_IS_FLOW(struct_flags) ) + if (type_name && memcmp(type_name, "binary", 6) == 0) + { + /* reset struct flag. in order not to print ']' */ + struct_flags = CV_NODE_SEQ; + sprintf(buf, "!!binary |"); + data = buf; + } + else if( CV_NODE_IS_FLOW(struct_flags)) { char c = CV_NODE_IS_MAP(struct_flags) ? '{' : '['; struct_flags |= CV_NODE_FLOW; @@ -1813,6 +2021,92 @@ icvXMLSkipSpaces( CvFileStorage* fs, char* ptr, int mode ) } +static void icvXMLGetMultilineStringContent(CvFileStorage* fs, + char* ptr, char* &beg, char* &end) +{ + ptr = icvXMLSkipSpaces(fs, ptr, CV_XML_INSIDE_TAG); + beg = ptr; + end = ptr; + if (fs->dummy_eof) + return ; /* end of file */ + + if (*beg == '<') + return; /* end of string */ + + /* find end */ + while(cv_isprint(*ptr)) /* no check for base64 string */ + ++ ptr; + if (*ptr == '\0') + CV_PARSE_ERROR("Unexpected end of line"); + + end = ptr; +} + + +static char* icvXMLParseBase64(CvFileStorage* fs, char* ptr, CvFileNode * node) +{ + char * beg = 0; + char * end = 0; + + icvXMLGetMultilineStringContent(fs, ptr, beg, end); + if (beg >= end) + return end; // CV_PARSE_ERROR("Empty Binary Data"); + + /* calc (decoded) total_byte_size from header */ + std::string dt; + int total_byte_size = -1; + { + if (end - beg < base64::ENCODED_HEADER_SIZE) + CV_PARSE_ERROR("Unrecognized Base64 header"); + + std::vector header(base64::HEADER_SIZE + 1, ' '); + base64::base64_decode(beg, header.data(), 0U, base64::ENCODED_HEADER_SIZE); + std::istringstream iss(header.data()); + if (!(iss >> total_byte_size) || total_byte_size < 0) + CV_PARSE_ERROR("Cannot parse size in Base64 header"); + if (!(iss >> dt) || dt.empty()) + CV_PARSE_ERROR("Cannot parse dt in Base64 header"); + + beg += base64::ENCODED_HEADER_SIZE; + } + + /* alloc buffer for all decoded data(include header) */ + std::vector buffer(total_byte_size + 4); + { + base64::Base64ContextParser parser(buffer.data(), total_byte_size + 4); + + /* decoding */ + while(beg < end) + { + /* save this part [beg, end) */ + parser.read((const uchar *)beg, (const uchar *)end); + beg = end; + /* find next part */ + icvXMLGetMultilineStringContent(fs, beg, beg, end); + } + } + + /* save as CvSeq */ + int elem_size = ::icvCalcStructSize(dt.c_str(), 0); + if (total_byte_size % elem_size != 0) + CV_PARSE_ERROR("Byte size not match elememt size"); + int elem_cnt = total_byte_size / elem_size; + + node->tag = CV_NODE_NONE; + int struct_flags = CV_NODE_SEQ; /* after icvFSCreateCollection, node->tag == struct_flags */ + icvFSCreateCollection(fs, struct_flags, node); + base64::make_seq(buffer.data(), elem_cnt, dt.c_str(), *node->data.seq); + + if (fs->dummy_eof) { + /* end of file */ + return fs->buffer_start; + } else { + /* end of line */ + return end; + } +} + + static char* icvXMLParseTag( CvFileStorage* fs, char* ptr, CvStringHashNode** _tag, CvAttrList** _list, int* _tag_type ); @@ -1864,6 +2158,9 @@ icvXMLParseValue( CvFileStorage* fs, char* ptr, CvFileNode* node, assert( tag_type == CV_XML_OPENING_TAG ); + /* for base64 string */ + bool is_binary_string = false; + type_name = list ? cvAttrValue( list, "type_id" ) : 0; if( type_name ) { @@ -1873,6 +2170,11 @@ icvXMLParseValue( CvFileStorage* fs, char* ptr, CvFileNode* node, elem_type = CV_NODE_MAP; else if( strcmp( type_name, "seq" ) == 0 ) elem_type = CV_NODE_SEQ; + else if (strcmp(type_name, "binary") == 0) + { + elem_type = CV_NODE_NONE; + is_binary_string = true; + } else { info = cvFindType( type_name ); @@ -1895,7 +2197,14 @@ icvXMLParseValue( CvFileStorage* fs, char* ptr, CvFileNode* node, else elem = cvGetFileNode( fs, node, key, 1 ); - ptr = icvXMLParseValue( fs, ptr, elem, elem_type); + if (!is_binary_string) + ptr = icvXMLParseValue( fs, ptr, elem, elem_type); + else { + /* for base64 string */ + ptr = icvXMLParseBase64( fs, ptr, elem); + ptr = icvXMLSkipSpaces( fs, ptr, 0 ); + } + if( !is_noname ) elem->tag |= CV_NODE_NAMED; is_simple &= !CV_NODE_IS_COLLECTION(elem->tag); @@ -2832,7 +3141,7 @@ cvOpenFileStorage( const char* filename, CvMemStorage* dststorage, int flags, co else { if( !append ) - icvPuts( fs, "%YAML:1.0\n" ); + icvPuts( fs, "%YAML 1.0\n---\n" ); else icvPuts( fs, "...\n---\n" ); fs->start_write_struct = icvYMLStartWriteStruct; @@ -2853,7 +3162,7 @@ cvOpenFileStorage( const char* filename, CvMemStorage* dststorage, int flags, co } size_t buf_size = 1 << 20; - const char* yaml_signature = "%YAML:"; + const char* yaml_signature = "%YAML"; char buf[16]; icvGets( fs, buf, sizeof(buf)-2 ); fs->fmt = strncmp( buf, yaml_signature, strlen(yaml_signature) ) == 0 ? @@ -3074,6 +3383,29 @@ icvCalcElemSize( const char* dt, int initial_size ) } +static int +icvCalcStructSize( const char* dt, int initial_size ) +{ + int size = icvCalcElemSize( dt, initial_size ); + int elem_max_size = 0; + for ( const char * type = dt; *type != '\0'; type++ ) { + switch ( *type ) + { + case 'u': { if (elem_max_size < sizeof(uchar)) elem_max_size = sizeof(uchar); break; } + case 'c': { if (elem_max_size < sizeof(schar)) elem_max_size = sizeof(schar); break; } + case 'w': { if (elem_max_size < sizeof(ushort)) elem_max_size = sizeof(ushort); break; } + case 's': { if (elem_max_size < sizeof(short)) elem_max_size = sizeof(short); break; } + case 'i': { if (elem_max_size < sizeof(int)) elem_max_size = sizeof(int); break; } + case 'f': { if (elem_max_size < sizeof(float)) elem_max_size = sizeof(float); break; } + case 'd': { if (elem_max_size < sizeof(double)) elem_max_size = sizeof(double); break; } + default: break; + } + } + size = cvAlign( size, elem_max_size ); + return size; +} + + static int icvDecodeSimpleFormat( const char* dt ) { @@ -3534,7 +3866,7 @@ static int icvFileNodeSeqLen( CvFileNode* node ) { return CV_NODE_IS_COLLECTION(node->tag) ? node->data.seq->total : - CV_NODE_TYPE(node->tag) != CV_NODE_NONE; + CV_NODE_TYPE(node->tag) != CV_NODE_NONE; } @@ -5680,4 +6012,1008 @@ void read(const FileNode& node, String& value, const String& default_value) } + + + + + + + + +/**************************************************************************** + * Newly added for Base64 + * + * + ***************************************************************************/ + + +/**************************************************************************** + * constant + ***************************************************************************/ + +#if CHAR_BIT != 8 +#error "`char` should be 8 bit." +#endif + +uint8_t const base64::base64_mapping[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; + +uint8_t const base64::base64_padding = '='; + +uint8_t const base64::base64_demapping[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 62, 0, 0, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 0, 0, 0, 0, +}; + +/* `base64_demapping` above is generated in this way: + * ````````````````````````````````````````````````````````````````````` + * std::string mapping((const char *)base64_mapping); + * for (auto ch = 0; ch < 127; ch++) { + * auto i = mapping.find(ch); + * printf("%3u, ", (i != std::string::npos ? i : 0)); + * } + * putchar('\n'); + * ````````````````````````````````````````````````````````````````````` + */ + +/**************************************************************************** + * function + ***************************************************************************/ + +size_t base64::base64_encode(uint8_t const * src, uint8_t * dst, size_t off, size_t cnt) +{ + if (!src || !dst || !cnt) + return 0; + + /* initialize beginning and end */ + uint8_t * dst_beg = dst; + uint8_t * dst_cur = dst_beg; + + uint8_t const * src_beg = src + off; + uint8_t const * src_cur = src_beg; + uint8_t const * src_end = src_cur + cnt / 3U * 3U; + + /* integer multiples part */ + while (src_cur < src_end) { + uint8_t _2 = *src_cur++; + uint8_t _1 = *src_cur++; + uint8_t _0 = *src_cur++; + *dst_cur++ = base64_mapping[ _2 >> 2U]; + *dst_cur++ = base64_mapping[(_1 & 0xF0U) >> 4U | (_2 & 0x03U) << 4U]; + *dst_cur++ = base64_mapping[(_0 & 0xC0U) >> 6U | (_1 & 0x0FU) << 2U]; + *dst_cur++ = base64_mapping[ _0 & 0x3FU]; + } + + /* remainder part */ + size_t rst = src_beg + cnt - src_cur; + if (rst == 1U) { + uint8_t _2 = *src_cur++; + *dst_cur++ = base64_mapping[ _2 >> 2U]; + *dst_cur++ = base64_mapping[(_2 & 0x03U) << 4U]; + } else if (rst == 2U) { + uint8_t _2 = *src_cur++; + uint8_t _1 = *src_cur++; + *dst_cur++ = base64_mapping[ _2 >> 2U]; + *dst_cur++ = base64_mapping[(_2 & 0x03U) << 4U | (_1 & 0xF0U) >> 4U]; + *dst_cur++ = base64_mapping[(_1 & 0x0FU) << 2U]; + } + + /* padding */ + switch (rst) + { + case 1U: *dst_cur++ = base64_padding; + case 2U: *dst_cur++ = base64_padding; + default: *dst_cur = 0; + break; + } + + return static_cast(dst_cur - dst_beg); +} + +size_t base64::base64_encode(char const * src, char * dst, size_t off, size_t cnt) +{ + if (cnt == 0U) + cnt = std::strlen(src); + + return base64_encode + ( + reinterpret_cast(src), + reinterpret_cast(dst), + off, + cnt + ); +} + +size_t base64::base64_decode(uint8_t const * src, uint8_t * dst, size_t off, size_t cnt) +{ + /* check parameters */ + if (!src || !dst || !cnt) + return 0U; + if (cnt & 0x3U) + return 0U; + + /* initialize beginning and end */ + uint8_t * dst_beg = dst; + uint8_t * dst_cur = dst_beg; + + uint8_t const * src_beg = src + off; + uint8_t const * src_cur = src_beg; + uint8_t const * src_end = src_cur + cnt; + + /* start decoding */ + while (src_cur < src_end) { + uint8_t d50 = base64_demapping[*src_cur++]; + uint8_t c50 = base64_demapping[*src_cur++]; + uint8_t b50 = base64_demapping[*src_cur++]; + uint8_t a50 = base64_demapping[*src_cur++]; + + uint8_t b10 = b50 & 0x03U; + uint8_t b52 = b50 & 0x3CU; + uint8_t c30 = c50 & 0x0FU; + uint8_t c54 = c50 & 0x30U; + + *dst_cur++ = (d50 << 2U) | (c54 >> 4U); + *dst_cur++ = (c30 << 4U) | (b52 >> 2U); + *dst_cur++ = (b10 << 6U) | (a50 >> 0U); + } + + *dst_cur = 0; + return size_t(dst_cur - dst_beg); +} + +size_t base64::base64_decode(char const * src, char * dst, size_t off, size_t cnt) +{ + if (cnt == 0U) + cnt = std::strlen(src); + + return base64_decode + ( + reinterpret_cast(src), + reinterpret_cast(dst), + off, + cnt + ); +} + +bool base64::base64_valid(uint8_t const * src, size_t off, size_t cnt) +{ + /* check parameters */ + if (src == nullptr || src + off == nullptr) + return false; + if (cnt == 0U) + cnt = std::strlen(reinterpret_cast(src)); + if (cnt & 0x3U) + return false; + + /* initialize beginning and end */ + uint8_t const * beg = src + off; + uint8_t const * end = beg + cnt; + + /* skip padding */ + if (*(end - 1U) == base64_padding) { + end--; + if (*(end - 1U) == base64_padding) + end--; + } + + /* find illegal characters */ + for (uint8_t const * iter = beg; iter < end; iter++) + if (*iter < 0 || (!base64_demapping[(uint8_t)*iter] && *iter != base64_mapping[0])) + return false; + + return true; +} + +bool base64::base64_valid(char const * src, size_t off, size_t cnt) +{ + if (cnt == 0U) + cnt = std::strlen(src); + + return base64_valid(reinterpret_cast(src), off, cnt); +} + +size_t base64::base64_encode_buffer_size(size_t cnt) +{ + return size_t((cnt + 2U) / 3U * 4U + 1U); +} + +size_t base64::base64_decode_buffer_size(size_t cnt) +{ + return size_t(cnt / 4U * 3U + 1U); +} + +/**************************************************************************** + * to_binary && binary_to + ***************************************************************************/ + +template inline size_t base64:: +to_binary(_uint_t val, uchar * cur) +{ + size_t cnt = sizeof(_uint_t); + while (cnt --> static_cast(0U)) { + *cur++ = static_cast(val); + val >>= CHAR_BIT; + } + return sizeof(_uint_t); +} + +template<> inline size_t base64::to_binary(double val, uchar * cur) +{ + Cv64suf bit64; + bit64.f = val; + return to_binary(bit64.u, cur); +} + +template<> inline size_t base64::to_binary(float val, uchar * cur) +{ + Cv32suf bit32; + bit32.f = val; + return to_binary(bit32.u, cur); +} + +template inline size_t base64:: +to_binary(uchar const * val, uchar * cur) +{ + return to_binary<_primitive_t>(*reinterpret_cast<_primitive_t const *>(val), cur); +} + + +template inline size_t base64:: +binary_to(uchar const * cur, _uint_t & val) +{ + val = static_cast<_uint_t>(0); + for (size_t i = static_cast(0U); i < sizeof(_uint_t); i++) + val |= (static_cast<_uint_t>(*cur++) << (i * CHAR_BIT)); + return sizeof(_uint_t); +} + +template<> inline size_t base64::binary_to(uchar const * cur, double & val) +{ + Cv64suf bit64; + binary_to(cur, bit64.u); + val = bit64.f; + return sizeof(val); +} + +template<> inline size_t base64::binary_to(uchar const * cur, float & val) +{ + Cv32suf bit32; + binary_to(cur, bit32.u); + val = bit32.f; + return sizeof(val); +} + +template inline size_t base64:: +binary_to(uchar const * cur, uchar * val) +{ + return binary_to<_primitive_t>(cur, *reinterpret_cast<_primitive_t *>(val)); +} + +/**************************************************************************** + * others + ***************************************************************************/ + +std::string base64::make_base64_header(int byte_size, const char * dt) +{ + int size = byte_size; + + std::ostringstream oss; + oss << size << ' ' + << dt << ' '; + std::string buffer(oss.str()); + if (buffer.size() > HEADER_SIZE) + CV_Assert(0); // error! header is too long + + buffer.reserve(HEADER_SIZE); + while (buffer.size() < HEADER_SIZE) + buffer += ' '; + + return buffer; +} + +bool base64::read_base64_header(std::string const & header, int & byte_size, std::string & dt) +{ + std::istringstream iss(header); + return static_cast(iss >> byte_size >> dt); +} + +/**************************************************************************** + * Parser + ***************************************************************************/ + +base64::Base64ContextParser::Base64ContextParser(uchar * buffer, size_t size) + : dst_beg(buffer) + , dst_cur(buffer) + , dst_end(buffer + size) + , base64_buffer(BUFFER_LEN) + , src_beg(0) + , src_end(0) + , src_cur(0) + , binary_buffer(base64_encode_buffer_size(BUFFER_LEN)) +{ + src_beg = binary_buffer.data(); + src_cur = src_beg; + src_end = src_beg + BUFFER_LEN; +} + +base64::Base64ContextParser::~Base64ContextParser() +{ + if (src_cur != src_beg) { + /* encode the rest binary data to base64 buffer */ + flush(); + } +} + +base64::Base64ContextParser & base64::Base64ContextParser:: +read(const uchar * beg, const uchar * end) +{ + if (beg >= end) + return *this; + + while (beg < end) { + /* collect binary data and copy to binary buffer */ + size_t len = std::min(end - beg, src_end - src_cur); + std::memcpy(src_cur, beg, len); + beg += len; + src_cur += len; + + if (src_cur >= src_end) { + /* binary buffer is full. */ + /* decode it send result to dst */ + + CV_Assert(flush()); /* check for base64_valid */ + } + } + + return *this; +} + +bool base64::Base64ContextParser::flush() +{ + if (!base64_valid(src_beg, 0U, src_cur - src_beg)) + return false; + + uchar * buffer = binary_buffer.data(); + size_t len = base64_decode(src_beg, buffer, 0U, src_cur - src_beg); + src_cur = src_beg; + + /* unexpected error */ + CV_Assert(len != 0); + + /* buffer is full */ + CV_Assert(dst_cur + len < dst_end); + + if (dst_cur + len < dst_end) { + /* send data to dst */ + std::memcpy(dst_cur, buffer, len); + dst_cur += len; + } + + return true; +} + +/**************************************************************************** + * Emitter + ***************************************************************************/ + +/* A decorator for CvFileStorage + * - no copyable + * - not safe for now + * - move constructor may be needed if C++11 + */ +class base64::Base64ContextEmitter +{ +public: + explicit Base64ContextEmitter(CvFileStorage * fs) + : file_storage(fs) + , binary_buffer(BUFFER_LEN) + , base64_buffer(base64_encode_buffer_size(BUFFER_LEN)) + , src_beg(0) + , src_end(0) + , src_cur(0) + { + src_beg = binary_buffer.data(); + src_end = src_beg + BUFFER_LEN; + src_cur = src_beg; + + // TODO: check if fs.state is valid. + + ::icvFSFlush(file_storage); + } + + ~Base64ContextEmitter() + { + /* cleaning */ + if (src_cur != src_beg) + flush(); /* encode the rest binary data to base64 buffer */ + } + + Base64ContextEmitter & write(const uchar * beg, const uchar * end) + { + if (beg >= end) + return *this; + + while (beg < end) { + /* collect binary data and copy to binary buffer */ + size_t len = std::min(end - beg, src_end - src_cur); + std::copy_n(beg, len, src_cur); + beg += len; + src_cur += len; + + if (src_cur >= src_end) { + /* binary buffer is full. */ + /* encode it to base64 and send result to fs */ + flush(); + } + } + + return *this; + } + + /* + * a convertor must provide : + * - `operator >> (uchar * & dst)` for writting current binary data to `dst` and moving to next data. + * - `operator bool` for checking if current loaction is valid and not the end. + */ + template inline + Base64ContextEmitter & write(_to_binary_convertor_t & convertor) + { + static const size_t BUFFER_MAX_LEN = 1024U; + + std::vector buffer(BUFFER_MAX_LEN); + uchar * beg = buffer.data(); + uchar * end = beg; + + while (convertor) { + convertor >> end; + write(beg, end); + end = beg; + } + + return *this; + } + + bool flush() + { + /* controll line width, so on. */ + size_t len = base64_encode(src_beg, base64_buffer.data(), 0U, src_cur - src_beg); + if (len == 0U) + return false; + + src_cur = src_beg; + { + // TODO: better solutions. + const char newline[] = "\n"; + char space[80]; + + int ident = file_storage->struct_indent; + memset(space, ' ', ident); + space[ident] = '\0'; + + ::icvPuts(file_storage, space); + ::icvPuts(file_storage, (const char*)base64_buffer.data()); + ::icvPuts(file_storage, newline); + ::icvFSFlush(file_storage); + } + + return true; + } + +private: + /* because of Base64, we must keep its length a multiple of 3 */ + static const size_t BUFFER_LEN = 51U; + // static_assert(BUFFER_LEN % 3 == 0, "BUFFER_LEN is invalid"); + +private: + CvFileStorage * file_storage; + + std::vector binary_buffer; + std::vector base64_buffer; + uchar * src_beg; + uchar * src_end; + uchar * src_cur; +}; + +class base64::MatToBinaryConvertor +{ +public: + + explicit MatToBinaryConvertor(const cv::Mat & src) + : y (0) + , y_max(0) + , x(0) + , x_max(0) + { + /* make sure each mat `mat.dims == 2` */ + if (src.dims > 2) { + const cv::Mat * arrays[] = { &src, 0 }; + cv::Mat plane; + cv::NAryMatIterator it(arrays, &plane, 1); + + CV_Assert(it.nplanes > 0U); /* make sure mats not empty */ + mats.reserve(it.nplanes); + for (size_t i = 0U; i < it.nplanes; ++i, ++it) + mats.push_back(*it.planes); + } else { + mats.push_back(src); + } + + /* set all to beginning */ + mat_iter = mats.begin(); + y_max = (mat_iter)->rows; + x_max = (mat_iter)->cols * (mat_iter)->elemSize(); + row_begin = (mat_iter)->ptr(0); + step = (mat_iter)->elemSize1(); + + /* choose a function */ + switch ((mat_iter)->depth()) + { + case CV_8U : + case CV_8S : { to_binary_func = to_binary ; break; } + case CV_16U: + case CV_16S: { to_binary_func = to_binary; break; } + case CV_32S: { to_binary_func = to_binary ; break; } + case CV_32F: { to_binary_func = to_binary ; break; } + case CV_64F: { to_binary_func = to_binary; break; } + case CV_USRTYPE1: + default: { CV_Assert(0); break; } + }; + + /* check if empty */ + if (mats.empty() || mats.front().empty() || mats.front().data == 0) { + mat_iter = mats.end(); + CV_Assert(!(*this)); + } + + } + + inline MatToBinaryConvertor & operator >> (uchar * & dst) + { + CV_DbgAssert(*this); + + /* copy to dst */ + dst += to_binary_func(row_begin + x, dst); + + /* move to next */ + x += step; + if (x >= x_max) { + /* when x arrive end, reset it and increase y */ + x = 0U; + ++ y; + if (y >= y_max) { + /* when y arrive end, reset it and increase iter */ + y = 0U; + ++ mat_iter; + if (mat_iter == mats.end()) { + ;/* when iter arrive end, all done */ + } else { + /* usually x_max and y_max won't change */ + y_max = (mat_iter)->rows; + x_max = (mat_iter)->cols * (mat_iter)->elemSize(); + row_begin = (mat_iter)->ptr(y); + } + } else + row_begin = (mat_iter)->ptr(y); + } + + return *this; + } + + inline explicit operator bool() const + { + return mat_iter != mats.end(); + } + +private: + + size_t x; + size_t x_max; + size_t y; + size_t y_max; + std::vector::iterator mat_iter; + std::vector mats; + + size_t step; + const uchar * row_begin; + + typedef size_t(*to_binary_t)(const uchar *, uchar *); + to_binary_t to_binary_func; +}; + +class base64::RawDataToBinaryConvertor +{ +public: + + RawDataToBinaryConvertor(const void* src, int len, const char* dt) + : beg(reinterpret_cast(src)) + , cur(0) + , end(0) + { + CV_Assert(src); + CV_Assert(dt); + CV_Assert(len > 0); + + /* calc step and to_binary_funcs */ + make_to_binary_funcs(dt); + + end = beg; + cur = beg; + + step = ::icvCalcStructSize(dt, 0); + end = beg + step * static_cast(len); + } + + inline RawDataToBinaryConvertor & operator >>(uchar * & dst) + { + CV_DbgAssert(*this); + + for (size_t i = 0U, n = to_binary_funcs.size(); i < n; i++) { + elem_to_binary_t & pack = to_binary_funcs[i]; + pack.func(cur + pack.offset, dst + pack.offset); + } + cur += step; + dst += step; + + return *this; + } + + inline explicit operator bool() const + { + return cur < end; + } + +private: + typedef size_t(*to_binary_t)(const uchar *, uchar *); + struct elem_to_binary_t + { + size_t offset; + to_binary_t func; + }; + +private: + void make_to_binary_funcs(const char* dt) + { + size_t cnt = 0; + size_t offset = 0; + char type = '\0'; + + std::istringstream iss(dt); + while (!iss.eof()) { + if (!(iss >> cnt)) { + iss.clear(); + cnt = 1; + } + CV_Assert(cnt > 0U); + if (!(iss >> type)) + break; + + while (cnt-- > 0) + { + to_binary_funcs.emplace_back(); + elem_to_binary_t & pack = to_binary_funcs.back(); + + size_t size = 0; + switch (type) + { + case 'u': + case 'c': + size = sizeof(uchar); + pack.func = to_binary; + break; + case 'w': + case 's': + size = sizeof(ushort); + pack.func = to_binary; + break; + case 'i': + size = sizeof(uint); + pack.func = to_binary; + break; + case 'f': + size = sizeof(float); + pack.func = to_binary; + break; + case 'd': + size = sizeof(double); + pack.func = to_binary; + break; + case 'r': + default: { CV_Assert(0); break; } + }; + + offset = static_cast(cvAlign(offset, size)); + pack.offset = offset; + offset += size; + } + } + + CV_Assert(iss.eof()); + } + +private: + const uchar * cur; + const uchar * beg; + const uchar * end; + + size_t step; + std::vector to_binary_funcs; +}; + +class base64::BinaryToCvSeqConvertor +{ +public: + BinaryToCvSeqConvertor(const void* src, int len, const char* dt) + : cur(reinterpret_cast(src)) + , beg(reinterpret_cast(src)) + , end(reinterpret_cast(src)) + { + CV_Assert(src); + CV_Assert(dt); + CV_Assert(len >= 0); + + /* calc binary_to_funcs */ + make_funcs(dt); + functor_iter = binary_to_funcs.begin(); + + step = ::icvCalcStructSize(dt, 0); + end = beg + step * static_cast(len); + } + + inline BinaryToCvSeqConvertor & operator >> (CvFileNode & dst) + { + CV_DbgAssert(*this); + + /* get current data */ + uchar buffer[sizeof(double)] = {0}; + functor_iter->func(cur + functor_iter->offset, buffer); + + /* set node::data */ + switch (functor_iter->cv_type) + { + case CV_8U : { dst.data.i = cv::saturate_cast (*reinterpret_cast(buffer)); break;} + case CV_8S : { dst.data.i = cv::saturate_cast (*reinterpret_cast(buffer)); break;} + case CV_16U: { dst.data.i = cv::saturate_cast (*reinterpret_cast(buffer)); break;} + case CV_16S: { dst.data.i = cv::saturate_cast (*reinterpret_cast(buffer)); break;} + case CV_32S: { dst.data.i = cv::saturate_cast (*reinterpret_cast(buffer)); break;} + case CV_32F: { dst.data.f = cv::saturate_cast(*reinterpret_cast(buffer)); break;} + case CV_64F: { dst.data.f = cv::saturate_cast(*reinterpret_cast(buffer)); break;} + default: break; + } + + /* set node::tag */ + switch (functor_iter->cv_type) + { + case CV_8U : + case CV_8S : + case CV_16U: + case CV_16S: + case CV_32S: { dst.tag = CV_NODE_INT; /*std::printf("%i,", dst.data.i);*/ break; } + case CV_32F: + case CV_64F: { dst.tag = CV_NODE_REAL; /*std::printf("%.1f,", dst.data.f);*/ break; } + default: break; + } + + /* check if end */ + if (++functor_iter == binary_to_funcs.end()) { + functor_iter = binary_to_funcs.begin(); + cur += step; + } + + return *this; + } + + inline explicit operator bool() const + { + return cur < end; + } + +private: + typedef size_t(*binary_to_t)(uchar const *, uchar *); + struct binary_to_filenode_t + { + size_t cv_type; + size_t offset; + binary_to_t func; + }; + +private: + void make_funcs(const char* dt) + { + size_t cnt = 0; + char type = '\0'; + int offset = 0; + + std::istringstream iss(dt); + while (!iss.eof()) { + if (!(iss >> cnt)) { + iss.clear(); + cnt = 1; + } + CV_Assert(cnt > 0U); + if (!(iss >> type)) + break; + + while (cnt-- > 0) + { + binary_to_funcs.emplace_back(); + binary_to_filenode_t & pack = binary_to_funcs.back(); + + /* set func and offset */ + size_t size = 0; + switch (type) + { + case 'u': + case 'c': + size = sizeof(uchar); + pack.func = binary_to; + break; + case 'w': + case 's': + size = sizeof(ushort); + pack.func = binary_to; + break; + case 'i': + size = sizeof(uint); + pack.func = binary_to; + break; + case 'f': + size = sizeof(float); + pack.func = binary_to; + break; + case 'd': + size = sizeof(double); + pack.func = binary_to; + break; + case 'r': + default: { CV_Assert(0); break; } + }; + + offset = static_cast(cvAlign(offset, size)); + pack.offset = offset; + offset += size; + + /* set type */ + switch (type) + { + case 'u': { pack.cv_type = CV_8U ; break; } + case 'c': { pack.cv_type = CV_8S ; break; } + case 'w': { pack.cv_type = CV_16U; break; } + case 's': { pack.cv_type = CV_16S; break; } + case 'i': { pack.cv_type = CV_32S; break; } + case 'f': { pack.cv_type = CV_32F; break; } + case 'd': { pack.cv_type = CV_64F; break; } + case 'r': + default: { CV_Assert(0); break; } + } + } + } + + CV_Assert(iss.eof()); + CV_Assert(binary_to_funcs.size()); + } + +private: + + const uchar * cur; + const uchar * beg; + const uchar * end; + + size_t step; + std::vector binary_to_funcs; + std::vector::iterator functor_iter; +}; + + + +/**************************************************************************** + * Wapper + ***************************************************************************/ + +void base64::make_seq(void * binary, int elem_cnt, const char * dt, CvSeq & seq) +{ + CvFileNode node; + node.info = 0; + BinaryToCvSeqConvertor convertor(binary, elem_cnt, dt); + while (convertor) { + convertor >> node; + cvSeqPush(&seq, &node); + } +} + +void base64::cvWriteRawData_Base64(cv::FileStorage & fs, const void* _data, int len, const char* dt) +{ + cvStartWriteStruct(*fs, fs.elname.c_str(), CV_NODE_SEQ, "binary"); + { + Base64ContextEmitter emitter(*fs); + { /* header */ + /* total byte size(before encode) */ + int size = len * ::icvCalcStructSize(dt, 0); + std::string buffer = make_base64_header(size, dt); + const uchar * beg = reinterpret_cast(buffer.data()); + const uchar * end = beg + buffer.size(); + + emitter.write(beg, end); + } + { /* body */ + RawDataToBinaryConvertor convert(_data, len, dt); + emitter.write(convert); + } + } + cvEndWriteStruct(*fs); +} + +void base64::cvWriteMat_Base64(cv::FileStorage & fs, cv::String const & name, cv::Mat const & mat) +{ + char dt[4]; + ::icvEncodeFormat(CV_MAT_TYPE(mat.type()), dt); + + { /* [1]output other attr */ + + if (mat.dims <= 2) { + cvStartWriteStruct(*fs, name.c_str(), CV_NODE_MAP, CV_TYPE_NAME_MAT); + + cvWriteInt(*fs, "rows", mat.rows ); + cvWriteInt(*fs, "cols", mat.cols ); + } else { + cvStartWriteStruct(*fs, name.c_str(), CV_NODE_MAP, CV_TYPE_NAME_MATND); + + cvStartWriteStruct(*fs, "sizes", CV_NODE_SEQ | CV_NODE_FLOW); + cvWriteRawData(*fs, mat.size.p, mat.dims, "i"); + cvEndWriteStruct(*fs); + } + cvWriteString(*fs, "dt", ::icvEncodeFormat(CV_MAT_TYPE(mat.type()), dt ), 0 ); + } + + cvStartWriteStruct(*fs, "data", CV_NODE_SEQ, "binary"); + { /* [2]deal with matrix's data */ + Base64ContextEmitter emitter(*fs); + + { /* [2][1]define base64 header */ + /* total byte size */ + int size = mat.total() * mat.elemSize(); + std::string buffer = make_base64_header(size, dt); + const uchar * beg = reinterpret_cast(buffer.data()); + const uchar * end = beg + buffer.size(); + + emitter.write(beg, end); + } + + { /* [2][2]base64 body */ + MatToBinaryConvertor convertor(mat); + + emitter.write(convertor); + } + } + cvEndWriteStruct(*fs); + + { /* [3]output end */ + cvEndWriteStruct(*fs); + } +} + +/**************************************************************************** + * Interface + ***************************************************************************/ + +namespace cv +{ + void cvWriteRawData_Base64(::cv::FileStorage & fs, const void* _data, int len, const char* dt) + { + ::base64::cvWriteRawData_Base64(fs, _data, len, dt); + } + + void cvWriteMat_Base64(::cv::FileStorage & fs, ::cv::String const & name, ::cv::Mat const & mat) + { + ::base64::cvWriteMat_Base64(fs, name, mat); + } +} + + /* End of file. */ diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index b53c43c83b..3e1cf6d1f9 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -577,3 +577,124 @@ TEST(Core_InputOutput, FileStorageKey) const std::string expected = "%YAML:1.0\nkey1: value1\n_key2: value2\nkey_3: value3\n"; ASSERT_STREQ(f.releaseAndGetString().c_str(), expected.c_str()); } + +TEST(Core_InputOutput, filestorage_yml_compatibility) +{ + //EXPECT_ANY_THROW(); +} + +TEST(Core_InputOutput, filestorage_yml_base64) +{ + cv::Mat _em_out, _em_in; + cv::Mat _2d_out, _2d_in; + cv::Mat _nd_out, _nd_in; + + { /* init */ + + /* normal mat */ + _2d_out = cv::Mat(1000, 1000, CV_8UC3, cvScalar(1U, 2U, 3U)); + for (int i = 0; i < _2d_out.rows; ++i) + for (int j = 0; j < _2d_out.cols; ++j) + _2d_out.at(i, j)[1] = i % 256; + + /* 4d mat */ + const int Size[] = {4, 4, 4, 4}; + cv::Mat _4d(4, Size, CV_32FC4); + const cv::Range ranges[] = { {0, 2}, {0, 2}, {1, 2}, {0, 2} }; + _nd_out = _4d(ranges); + } + + { /* write */ + cv::FileStorage fs("test.yml", cv::FileStorage::WRITE); + cv::cvWriteMat_Base64(fs, "normal_2d_mat", _2d_out); + cv::cvWriteMat_Base64(fs, "normal_nd_mat", _nd_out); + cv::cvWriteMat_Base64(fs, "empty_2d_mat", _em_out); + fs.release(); + } + + { /* read */ + cv::FileStorage fs("test.yml", cv::FileStorage::READ); + fs["empty_2d_mat"] >> _em_in; + fs["normal_2d_mat"] >> _2d_in; + fs["normal_nd_mat"] >> _nd_in; + fs.release(); + } + + EXPECT_EQ(_em_in.rows , _em_out.rows); + EXPECT_EQ(_em_in.cols , _em_out.cols); + EXPECT_EQ(_em_in.dims , _em_out.dims); + EXPECT_EQ(_em_in.depth(), _em_out.depth()); + EXPECT_TRUE(_em_in.empty()); + + EXPECT_EQ(_2d_in.rows , _2d_in.rows); + EXPECT_EQ(_2d_in.cols , _2d_in.cols); + EXPECT_EQ(_2d_in.dims , _2d_in.dims); + EXPECT_EQ(_2d_in.depth(), _2d_in.depth()); + for(int i = 0; i < _2d_in.rows; ++i) + for (int j = 0; j < _2d_in.cols; ++j) + EXPECT_EQ(_2d_in.at(i, j), _2d_out.at(i, j)); + + EXPECT_EQ(_nd_in.rows , _nd_in.rows); + EXPECT_EQ(_nd_in.cols , _nd_in.cols); + EXPECT_EQ(_nd_in.dims , _nd_in.dims); + EXPECT_EQ(_nd_in.depth(), _nd_in.depth()); + EXPECT_EQ(cv::countNonZero(cv::mean(_nd_in != _nd_out)), 0); +} + +TEST(Core_InputOutput, filestorage_xml_base64) +{ + cv::Mat _em_out, _em_in; + cv::Mat _2d_out, _2d_in; + cv::Mat _nd_out, _nd_in; + + { /* init */ + + /* normal mat */ + _2d_out = cv::Mat(1000, 1000, CV_8UC3, cvScalar(1U, 2U, 3U)); + for (int i = 0; i < _2d_out.rows; ++i) + for (int j = 0; j < _2d_out.cols; ++j) + _2d_out.at(i, j)[1] = i % 256; + + /* 4d mat */ + const int Size[] = {4, 4, 4, 4}; + cv::Mat _4d(4, Size, CV_32FC4); + const cv::Range ranges[] = { {0, 2}, {0, 2}, {1, 2}, {0, 2} }; + _nd_out = _4d(ranges); + } + + { /* write */ + cv::FileStorage fs("test.xml", cv::FileStorage::WRITE); + cv::cvWriteMat_Base64(fs, "normal_2d_mat", _2d_out); + cv::cvWriteMat_Base64(fs, "normal_nd_mat", _nd_out); + cv::cvWriteMat_Base64(fs, "empty_2d_mat", _em_out); + fs.release(); + } + + { /* read */ + cv::FileStorage fs("test.xml", cv::FileStorage::READ); + fs["empty_2d_mat"] >> _em_in; + fs["normal_2d_mat"] >> _2d_in; + fs["normal_nd_mat"] >> _nd_in; + fs.release(); + } + + EXPECT_EQ(_em_in.rows , _em_out.rows); + EXPECT_EQ(_em_in.cols , _em_out.cols); + EXPECT_EQ(_em_in.dims , _em_out.dims); + EXPECT_EQ(_em_in.depth(), _em_out.depth()); + EXPECT_TRUE(_em_in.empty()); + + EXPECT_EQ(_2d_in.rows , _2d_in.rows); + EXPECT_EQ(_2d_in.cols , _2d_in.cols); + EXPECT_EQ(_2d_in.dims , _2d_in.dims); + EXPECT_EQ(_2d_in.depth(), _2d_in.depth()); + for(int i = 0; i < _2d_in.rows; ++i) + for (int j = 0; j < _2d_in.cols; ++j) + EXPECT_EQ(_2d_in.at(i, j), _2d_out.at(i, j)); + + EXPECT_EQ(_nd_in.rows , _nd_in.rows); + EXPECT_EQ(_nd_in.cols , _nd_in.cols); + EXPECT_EQ(_nd_in.dims , _nd_in.dims); + EXPECT_EQ(_nd_in.depth(), _nd_in.depth()); + EXPECT_EQ(cv::countNonZero(cv::mean(_nd_in != _nd_out)), 0); +} From 7b1f7c8d8ede055df30e1d819e8de3b73dff8b7a Mon Sep 17 00:00:00 2001 From: MYLS Date: Sat, 18 Jun 2016 22:13:49 +0800 Subject: [PATCH 05/30] Add Base64 support for FileStorage 1. Add Base64 support for reading and writing XML\YML file. The two new functions for writing: ```cpp void cvWriteRawData_Base64(cv::FileStorage & fs, const void* _data, int len, const char* dt); void cvWriteMat_Base64(cv::FileStorage & fs, cv::String const & name, cv::Mat const & mat); ``` 2. Change YML file header form `YAML:1.0` to `YAML 1.0`. (standard format) 3. Add test for Base64 part. --- modules/core/test/test_io.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 3e1cf6d1f9..a36b212cdf 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -574,7 +574,7 @@ TEST(Core_InputOutput, FileStorageKey) EXPECT_NO_THROW(f << "key1" << "value1"); EXPECT_NO_THROW(f << "_key2" << "value2"); EXPECT_NO_THROW(f << "key_3" << "value3"); - const std::string expected = "%YAML:1.0\nkey1: value1\n_key2: value2\nkey_3: value3\n"; + const std::string expected = "%YAML 1.0\n---\nkey1: value1\n_key2: value2\nkey_3: value3\n"; ASSERT_STREQ(f.releaseAndGetString().c_str(), expected.c_str()); } From d1b097f409bf4bb3366953ddc36f967760083e83 Mon Sep 17 00:00:00 2001 From: MYLS Date: Sat, 18 Jun 2016 23:28:12 +0800 Subject: [PATCH 06/30] fix most coding style warnings and errors --- modules/core/src/persistence.cpp | 64 ++++++++++++++++---------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index 4f323984bf..9c44e0c46a 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -298,9 +298,9 @@ namespace base64 bool flush(); private: static const size_t BUFFER_LEN = 120U; + uchar * dst_beg; uchar * dst_cur; uchar * dst_end; - uchar * dst_beg; std::vector base64_buffer; uchar * src_beg; uchar * src_end; @@ -1114,7 +1114,7 @@ static char* icvYMLParseBase64(CvFileStorage* fs, char* ptr, int indent, CvFileN std::string dt; int total_byte_size = -1; { - if (end - beg < base64::ENCODED_HEADER_SIZE) + if (end - beg < static_cast(base64::ENCODED_HEADER_SIZE)) CV_PARSE_ERROR("Unrecognized Base64 header"); std::vector header(base64::HEADER_SIZE + 1, ' '); @@ -1294,7 +1294,7 @@ icvYMLParseValue( CvFileStorage* fs, char* ptr, CvFileNode* node, if (is_binary_string) { /* for base64 string */ - int indent = ptr - fs->buffer_start; + int indent = static_cast(ptr - fs->buffer_start); ptr = icvYMLParseBase64(fs, ptr, indent, node); } else if( cv_isdigit(c) || @@ -2056,7 +2056,7 @@ static char* icvXMLParseBase64(CvFileStorage* fs, char* ptr, CvFileNode * node) std::string dt; int total_byte_size = -1; { - if (end - beg < base64::ENCODED_HEADER_SIZE) + if (end - beg < static_cast(base64::ENCODED_HEADER_SIZE)) CV_PARSE_ERROR("Unrecognized Base64 header"); std::vector header(base64::HEADER_SIZE + 1, ' '); @@ -3387,7 +3387,7 @@ static int icvCalcStructSize( const char* dt, int initial_size ) { int size = icvCalcElemSize( dt, initial_size ); - int elem_max_size = 0; + size_t elem_max_size = 0; for ( const char * type = dt; *type != '\0'; type++ ) { switch ( *type ) { @@ -3401,7 +3401,7 @@ icvCalcStructSize( const char* dt, int initial_size ) default: break; } } - size = cvAlign( size, elem_max_size ); + size = cvAlign( size, static_cast(elem_max_size) ); return size; } @@ -6035,14 +6035,14 @@ void read(const FileNode& node, String& value, const String& default_value) #error "`char` should be 8 bit." #endif -uint8_t const base64::base64_mapping[] = +base64::uint8_t const base64::base64_mapping[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; -uint8_t const base64::base64_padding = '='; +base64::uint8_t const base64::base64_padding = '='; -uint8_t const base64::base64_demapping[] = { +base64::uint8_t const base64::base64_demapping[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, @@ -6185,7 +6185,7 @@ size_t base64::base64_decode(char const * src, char * dst, size_t off, size_t cn bool base64::base64_valid(uint8_t const * src, size_t off, size_t cnt) { /* check parameters */ - if (src == nullptr || src + off == nullptr) + if (src == 0 || src + off == 0) return false; if (cnt == 0U) cnt = std::strlen(reinterpret_cast(src)); @@ -6205,7 +6205,7 @@ bool base64::base64_valid(uint8_t const * src, size_t off, size_t cnt) /* find illegal characters */ for (uint8_t const * iter = beg; iter < end; iter++) - if (*iter < 0 || (!base64_demapping[(uint8_t)*iter] && *iter != base64_mapping[0])) + if (*iter > 126U || (!base64_demapping[(uint8_t)*iter] && *iter != base64_mapping[0])) return false; return true; @@ -6308,8 +6308,8 @@ std::string base64::make_base64_header(int byte_size, const char * dt) oss << size << ' ' << dt << ' '; std::string buffer(oss.str()); - if (buffer.size() > HEADER_SIZE) - CV_Assert(0); // error! header is too long + if (buffer.size() > HEADER_SIZE) { + CV_Assert(0); } buffer.reserve(HEADER_SIZE); while (buffer.size() < HEADER_SIZE) @@ -6334,8 +6334,8 @@ base64::Base64ContextParser::Base64ContextParser(uchar * buffer, size_t size) , dst_end(buffer + size) , base64_buffer(BUFFER_LEN) , src_beg(0) - , src_end(0) , src_cur(0) + , src_end(0) , binary_buffer(base64_encode_buffer_size(BUFFER_LEN)) { src_beg = binary_buffer.data(); @@ -6443,7 +6443,7 @@ public: while (beg < end) { /* collect binary data and copy to binary buffer */ size_t len = std::min(end - beg, src_end - src_cur); - std::copy_n(beg, len, src_cur); + std::memcpy(src_cur, beg, len); beg += len; src_cur += len; @@ -6597,26 +6597,26 @@ public: /* usually x_max and y_max won't change */ y_max = (mat_iter)->rows; x_max = (mat_iter)->cols * (mat_iter)->elemSize(); - row_begin = (mat_iter)->ptr(y); + row_begin = (mat_iter)->ptr(static_cast(y)); } } else - row_begin = (mat_iter)->ptr(y); + row_begin = (mat_iter)->ptr(static_cast(y)); } return *this; } - inline explicit operator bool() const + inline operator bool() const { return mat_iter != mats.end(); } private: - size_t x; - size_t x_max; size_t y; size_t y_max; + size_t x; + size_t x_max; std::vector::iterator mat_iter; std::vector mats; @@ -6664,7 +6664,7 @@ public: return *this; } - inline explicit operator bool() const + inline operator bool() const { return cur < end; } @@ -6696,8 +6696,7 @@ private: while (cnt-- > 0) { - to_binary_funcs.emplace_back(); - elem_to_binary_t & pack = to_binary_funcs.back(); + elem_to_binary_t pack; size_t size = 0; switch (type) @@ -6728,9 +6727,11 @@ private: default: { CV_Assert(0); break; } }; - offset = static_cast(cvAlign(offset, size)); + offset = static_cast(cvAlign(static_cast(offset), static_cast(size))); pack.offset = offset; offset += size; + + to_binary_funcs.push_back(pack); } } @@ -6738,8 +6739,8 @@ private: } private: - const uchar * cur; const uchar * beg; + const uchar * cur; const uchar * end; size_t step; @@ -6809,7 +6810,7 @@ public: return *this; } - inline explicit operator bool() const + inline operator bool() const { return cur < end; } @@ -6842,8 +6843,7 @@ private: while (cnt-- > 0) { - binary_to_funcs.emplace_back(); - binary_to_filenode_t & pack = binary_to_funcs.back(); + binary_to_filenode_t pack; /* set func and offset */ size_t size = 0; @@ -6875,9 +6875,9 @@ private: default: { CV_Assert(0); break; } }; - offset = static_cast(cvAlign(offset, size)); + offset = static_cast(cvAlign(static_cast(offset), static_cast(size))); pack.offset = offset; - offset += size; + offset += static_cast(size); /* set type */ switch (type) @@ -6892,6 +6892,8 @@ private: case 'r': default: { CV_Assert(0); break; } } + + binary_to_funcs.push_back(pack); } } @@ -6977,7 +6979,7 @@ void base64::cvWriteMat_Base64(cv::FileStorage & fs, cv::String const & name, cv { /* [2][1]define base64 header */ /* total byte size */ - int size = mat.total() * mat.elemSize(); + int size = static_cast(mat.total() * mat.elemSize()); std::string buffer = make_base64_header(size, dt); const uchar * beg = reinterpret_cast(buffer.data()); const uchar * end = beg + buffer.size(); From 882e4221e722c92d419d86b2b94ad8c5fc1fd574 Mon Sep 17 00:00:00 2001 From: MYLS Date: Sun, 19 Jun 2016 00:45:51 +0800 Subject: [PATCH 07/30] fix errors from test. Two other test are still needed. 1. Verify the Base64 data. 2. Read an old YML file for compatibility test. --- modules/core/src/persistence.cpp | 55 +++++++++++++++++++------------- modules/core/test/test_io.cpp | 12 +++++-- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index 9c44e0c46a..d1514ec308 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -303,8 +303,8 @@ namespace base64 uchar * dst_end; std::vector base64_buffer; uchar * src_beg; - uchar * src_end; uchar * src_cur; + uchar * src_end; std::vector binary_buffer; }; @@ -3498,7 +3498,7 @@ cvWriteRawData( CvFileStorage* fs, const void* _data, int len, const char* dt ) data += sizeof(size_t); break; default: - assert(0); + CV_Assert(!"elem_type is not support."); return; } @@ -3620,7 +3620,7 @@ cvReadRawDataSlice( const CvFileStorage* fs, CvSeqReader* reader, data += sizeof(size_t); break; default: - assert(0); + CV_Assert(0); return; } } @@ -3670,7 +3670,7 @@ cvReadRawDataSlice( const CvFileStorage* fs, CvSeqReader* reader, data += sizeof(size_t); break; default: - assert(0); + CV_Assert(0); return; } } @@ -6236,10 +6236,11 @@ size_t base64::base64_decode_buffer_size(size_t cnt) template inline size_t base64:: to_binary(_uint_t val, uchar * cur) { + size_t delta = CHAR_BIT; size_t cnt = sizeof(_uint_t); while (cnt --> static_cast(0U)) { *cur++ = static_cast(val); - val >>= CHAR_BIT; + val >>= delta; } return sizeof(_uint_t); } @@ -6308,8 +6309,7 @@ std::string base64::make_base64_header(int byte_size, const char * dt) oss << size << ' ' << dt << ' '; std::string buffer(oss.str()); - if (buffer.size() > HEADER_SIZE) { - CV_Assert(0); } + CV_Assert(buffer.size() < HEADER_SIZE); buffer.reserve(HEADER_SIZE); while (buffer.size() < HEADER_SIZE) @@ -6563,7 +6563,7 @@ public: case CV_32F: { to_binary_func = to_binary ; break; } case CV_64F: { to_binary_func = to_binary; break; } case CV_USRTYPE1: - default: { CV_Assert(0); break; } + default: { CV_Assert(!"mat type is invalid"); break; } }; /* check if empty */ @@ -6724,7 +6724,7 @@ private: pack.func = to_binary; break; case 'r': - default: { CV_Assert(0); break; } + default: { CV_Assert(!"type not support"); break; } }; offset = static_cast(cvAlign(static_cast(offset), static_cast(size))); @@ -6772,19 +6772,30 @@ public: CV_DbgAssert(*this); /* get current data */ - uchar buffer[sizeof(double)] = {0}; - functor_iter->func(cur + functor_iter->offset, buffer); + union + { + uchar mem[sizeof(double)]; + uchar u; + char b; + ushort w; + short s; + int i; + float f; + double d; + } buffer; /* for GCC -Wstrict-aliasing */ + std::memset(buffer.mem, 0, sizeof(buffer)); + functor_iter->func(cur + functor_iter->offset, buffer.mem); /* set node::data */ switch (functor_iter->cv_type) { - case CV_8U : { dst.data.i = cv::saturate_cast (*reinterpret_cast(buffer)); break;} - case CV_8S : { dst.data.i = cv::saturate_cast (*reinterpret_cast(buffer)); break;} - case CV_16U: { dst.data.i = cv::saturate_cast (*reinterpret_cast(buffer)); break;} - case CV_16S: { dst.data.i = cv::saturate_cast (*reinterpret_cast(buffer)); break;} - case CV_32S: { dst.data.i = cv::saturate_cast (*reinterpret_cast(buffer)); break;} - case CV_32F: { dst.data.f = cv::saturate_cast(*reinterpret_cast(buffer)); break;} - case CV_64F: { dst.data.f = cv::saturate_cast(*reinterpret_cast(buffer)); break;} + case CV_8U : { dst.data.i = cv::saturate_cast (buffer.u); break;} + case CV_8S : { dst.data.i = cv::saturate_cast (buffer.b); break;} + case CV_16U: { dst.data.i = cv::saturate_cast (buffer.w); break;} + case CV_16S: { dst.data.i = cv::saturate_cast (buffer.s); break;} + case CV_32S: { dst.data.i = cv::saturate_cast (buffer.i); break;} + case CV_32F: { dst.data.f = cv::saturate_cast(buffer.f); break;} + case CV_64F: { dst.data.f = cv::saturate_cast(buffer.d); break;} default: break; } @@ -6872,8 +6883,8 @@ private: pack.func = binary_to; break; case 'r': - default: { CV_Assert(0); break; } - }; + default: { CV_Assert(!"type not support"); break; } + }; // need a better way for outputting error. offset = static_cast(cvAlign(static_cast(offset), static_cast(size))); pack.offset = offset; @@ -6890,8 +6901,8 @@ private: case 'f': { pack.cv_type = CV_32F; break; } case 'd': { pack.cv_type = CV_64F; break; } case 'r': - default: { CV_Assert(0); break; } - } + default: { CV_Assert(!"type is not support"); break; } + } // need a better way for outputting error. binary_to_funcs.push_back(pack); } diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index a36b212cdf..8ef91a8b2e 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -600,7 +600,11 @@ TEST(Core_InputOutput, filestorage_yml_base64) /* 4d mat */ const int Size[] = {4, 4, 4, 4}; cv::Mat _4d(4, Size, CV_32FC4); - const cv::Range ranges[] = { {0, 2}, {0, 2}, {1, 2}, {0, 2} }; + const cv::Range ranges[] = { + cv::Range(0, 2), + cv::Range(0, 2), + cv::Range(1, 2), + cv::Range(0, 2) }; _nd_out = _4d(ranges); } @@ -658,7 +662,11 @@ TEST(Core_InputOutput, filestorage_xml_base64) /* 4d mat */ const int Size[] = {4, 4, 4, 4}; cv::Mat _4d(4, Size, CV_32FC4); - const cv::Range ranges[] = { {0, 2}, {0, 2}, {1, 2}, {0, 2} }; + const cv::Range ranges[] = { + cv::Range(0, 2), + cv::Range(0, 2), + cv::Range(1, 2), + cv::Range(0, 2) }; _nd_out = _4d(ranges); } From 958263d24556c5ce59d3b50df41b81276e657c14 Mon Sep 17 00:00:00 2001 From: MYLS Date: Sun, 19 Jun 2016 02:00:32 +0800 Subject: [PATCH 08/30] Solve warnings, and adjusted the test case. --- modules/core/src/persistence.cpp | 6 +++--- modules/core/test/test_io.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index d1514ec308..278ac6f0c9 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -3498,7 +3498,7 @@ cvWriteRawData( CvFileStorage* fs, const void* _data, int len, const char* dt ) data += sizeof(size_t); break; default: - CV_Assert(!"elem_type is not support."); + CV_Error( CV_StsUnsupportedFormat, "Unsupported type" ); return; } @@ -3620,7 +3620,7 @@ cvReadRawDataSlice( const CvFileStorage* fs, CvSeqReader* reader, data += sizeof(size_t); break; default: - CV_Assert(0); + CV_Error( CV_StsUnsupportedFormat, "Unsupported type" ); return; } } @@ -3670,7 +3670,7 @@ cvReadRawDataSlice( const CvFileStorage* fs, CvSeqReader* reader, data += sizeof(size_t); break; default: - CV_Assert(0); + CV_Error( CV_StsUnsupportedFormat, "Unsupported type" ); return; } } diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 8ef91a8b2e..1410b26d29 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -592,14 +592,14 @@ TEST(Core_InputOutput, filestorage_yml_base64) { /* init */ /* normal mat */ - _2d_out = cv::Mat(1000, 1000, CV_8UC3, cvScalar(1U, 2U, 3U)); + _2d_out = cv::Mat(100, 100, CV_8UC3, cvScalar(1U, 2U, 127U)); for (int i = 0; i < _2d_out.rows; ++i) for (int j = 0; j < _2d_out.cols; ++j) _2d_out.at(i, j)[1] = i % 256; /* 4d mat */ const int Size[] = {4, 4, 4, 4}; - cv::Mat _4d(4, Size, CV_32FC4); + cv::Mat _4d(4, Size, CV_64FC4, cvScalar(0.888, 0.111, 0.666, 0.444)); const cv::Range ranges[] = { cv::Range(0, 2), cv::Range(0, 2), @@ -654,14 +654,14 @@ TEST(Core_InputOutput, filestorage_xml_base64) { /* init */ /* normal mat */ - _2d_out = cv::Mat(1000, 1000, CV_8UC3, cvScalar(1U, 2U, 3U)); + _2d_out = cv::Mat(100, 100, CV_8UC3, cvScalar(1U, 2U, 127U)); for (int i = 0; i < _2d_out.rows; ++i) for (int j = 0; j < _2d_out.cols; ++j) _2d_out.at(i, j)[1] = i % 256; /* 4d mat */ const int Size[] = {4, 4, 4, 4}; - cv::Mat _4d(4, Size, CV_32FC4); + cv::Mat _4d(4, Size, CV_64FC4, cvScalar(0.888, 0.111, 0.666, 0.444)); const cv::Range ranges[] = { cv::Range(0, 2), cv::Range(0, 2), @@ -704,5 +704,5 @@ TEST(Core_InputOutput, filestorage_xml_base64) EXPECT_EQ(_nd_in.cols , _nd_in.cols); EXPECT_EQ(_nd_in.dims , _nd_in.dims); EXPECT_EQ(_nd_in.depth(), _nd_in.depth()); - EXPECT_EQ(cv::countNonZero(cv::mean(_nd_in != _nd_out)), 0); + EXPECT_EQ(cv::countNonZero(cv::sum(_nd_in != _nd_out)), 0); } From 9faa2a7fd01fc8856dbedb4f133757e8aea194ec Mon Sep 17 00:00:00 2001 From: MYLS Date: Sun, 19 Jun 2016 02:44:39 +0800 Subject: [PATCH 09/30] solve warning for IOS Two test are still needed: 1. Verify the Base64 data. 2. Read an old YML file for compatibility test. --- modules/core/src/persistence.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index 278ac6f0c9..ad8f9eaab1 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -298,7 +298,6 @@ namespace base64 bool flush(); private: static const size_t BUFFER_LEN = 120U; - uchar * dst_beg; uchar * dst_cur; uchar * dst_end; std::vector base64_buffer; @@ -6329,8 +6328,7 @@ bool base64::read_base64_header(std::string const & header, int & byte_size, std ***************************************************************************/ base64::Base64ContextParser::Base64ContextParser(uchar * buffer, size_t size) - : dst_beg(buffer) - , dst_cur(buffer) + : dst_cur(buffer) , dst_end(buffer + size) , base64_buffer(BUFFER_LEN) , src_beg(0) @@ -6840,7 +6838,7 @@ private: { size_t cnt = 0; char type = '\0'; - int offset = 0; + size_t offset = 0; std::istringstream iss(dt); while (!iss.eof()) { @@ -6888,7 +6886,7 @@ private: offset = static_cast(cvAlign(static_cast(offset), static_cast(size))); pack.offset = offset; - offset += static_cast(size); + offset += size; /* set type */ switch (type) From 29921d055df344b44fd5fbd92b80f58b93216886 Mon Sep 17 00:00:00 2001 From: MYLS Date: Mon, 20 Jun 2016 16:59:58 +0800 Subject: [PATCH 10/30] change the parameter to `CvMat` and `CvMatND` ```cpp cvWriteMat_Base64(::cv::FileStorage & fs, ::cv::String const & name, ::cv::Mat const & mat) ``` becomes: ```cpp CV_EXPORTS void cvWriteMat_Base64(::CvFileStorage* fs, const char* name, const ::CvMat* mat); CV_EXPORTS void cvWriteMatND_Base64(::CvFileStorage* fs, const char* name, const ::CvMatND* mat); ``` --- .../core/include/opencv2/core/persistence.hpp | 8 +++- modules/core/src/persistence.cpp | 39 +++++++++++-------- modules/core/test/test_io.cpp | 18 ++++++--- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/modules/core/include/opencv2/core/persistence.hpp b/modules/core/include/opencv2/core/persistence.hpp index 23714868bd..6ceeca438b 100644 --- a/modules/core/include/opencv2/core/persistence.hpp +++ b/modules/core/include/opencv2/core/persistence.hpp @@ -89,6 +89,8 @@ the extension of the opened file, ".xml" for XML files and ".yml" or ".yaml" for */ typedef struct CvFileStorage CvFileStorage; typedef struct CvFileNode CvFileNode; +typedef struct CvMat CvMat; +typedef struct CvMatND CvMatND; //! @} core_c @@ -1239,9 +1241,11 @@ inline String::String(const FileNode& fn): cstr_(0), len_(0) { read(fn, *this, * //! @endcond -CV_EXPORTS void cvWriteRawData_Base64(::cv::FileStorage & fs, const void* _data, int len, const char* dt); +CV_EXPORTS void cvWriteRawData_Base64(FileStorage & fs, const void* _data, int len, const char* dt); -CV_EXPORTS void cvWriteMat_Base64(::cv::FileStorage & fs, ::cv::String const & name, ::cv::Mat const & mat); +CV_EXPORTS void cvWriteMat_Base64(::CvFileStorage* fs, const char* name, const ::CvMat* mat); + +CV_EXPORTS void cvWriteMatND_Base64(::CvFileStorage* fs, const char* name, const ::CvMatND* mat); } // cv diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index ad8f9eaab1..fade7a71a4 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -320,7 +320,7 @@ namespace base64 /* sample */ void cvWriteRawData_Base64(::cv::FileStorage & fs, const void* _data, int len, const char* dt); - void cvWriteMat_Base64(::cv::FileStorage & fs, ::cv::String const & name, ::cv::Mat const & mat); + void cvWriteMat_Base64(CvFileStorage * fs, const char * name, ::cv::Mat const & mat); } @@ -6960,7 +6960,7 @@ void base64::cvWriteRawData_Base64(cv::FileStorage & fs, const void* _data, int cvEndWriteStruct(*fs); } -void base64::cvWriteMat_Base64(cv::FileStorage & fs, cv::String const & name, cv::Mat const & mat) +void base64::cvWriteMat_Base64(CvFileStorage * fs, const char * name, cv::Mat const & mat) { char dt[4]; ::icvEncodeFormat(CV_MAT_TYPE(mat.type()), dt); @@ -6968,23 +6968,23 @@ void base64::cvWriteMat_Base64(cv::FileStorage & fs, cv::String const & name, cv { /* [1]output other attr */ if (mat.dims <= 2) { - cvStartWriteStruct(*fs, name.c_str(), CV_NODE_MAP, CV_TYPE_NAME_MAT); + cvStartWriteStruct(fs, name, CV_NODE_MAP, CV_TYPE_NAME_MAT); - cvWriteInt(*fs, "rows", mat.rows ); - cvWriteInt(*fs, "cols", mat.cols ); + cvWriteInt(fs, "rows", mat.rows ); + cvWriteInt(fs, "cols", mat.cols ); } else { - cvStartWriteStruct(*fs, name.c_str(), CV_NODE_MAP, CV_TYPE_NAME_MATND); + cvStartWriteStruct(fs, name, CV_NODE_MAP, CV_TYPE_NAME_MATND); - cvStartWriteStruct(*fs, "sizes", CV_NODE_SEQ | CV_NODE_FLOW); - cvWriteRawData(*fs, mat.size.p, mat.dims, "i"); - cvEndWriteStruct(*fs); + cvStartWriteStruct(fs, "sizes", CV_NODE_SEQ | CV_NODE_FLOW); + cvWriteRawData(fs, mat.size.p, mat.dims, "i"); + cvEndWriteStruct(fs); } - cvWriteString(*fs, "dt", ::icvEncodeFormat(CV_MAT_TYPE(mat.type()), dt ), 0 ); + cvWriteString(fs, "dt", ::icvEncodeFormat(CV_MAT_TYPE(mat.type()), dt ), 0 ); } - cvStartWriteStruct(*fs, "data", CV_NODE_SEQ, "binary"); + cvStartWriteStruct(fs, "data", CV_NODE_SEQ, "binary"); { /* [2]deal with matrix's data */ - Base64ContextEmitter emitter(*fs); + Base64ContextEmitter emitter(fs); { /* [2][1]define base64 header */ /* total byte size */ @@ -7002,10 +7002,10 @@ void base64::cvWriteMat_Base64(cv::FileStorage & fs, cv::String const & name, cv emitter.write(convertor); } } - cvEndWriteStruct(*fs); + cvEndWriteStruct(fs); { /* [3]output end */ - cvEndWriteStruct(*fs); + cvEndWriteStruct(fs); } } @@ -7020,9 +7020,16 @@ namespace cv ::base64::cvWriteRawData_Base64(fs, _data, len, dt); } - void cvWriteMat_Base64(::cv::FileStorage & fs, ::cv::String const & name, ::cv::Mat const & mat) + void cvWriteMat_Base64(::CvFileStorage* fs, const char* name, const ::CvMat* mat) { - ::base64::cvWriteMat_Base64(fs, name, mat); + ::cv::Mat holder = ::cv::cvarrToMat(mat); + ::base64::cvWriteMat_Base64(fs, name, holder); + } + + void cvWriteMatND_Base64(::CvFileStorage* fs, const char* name, const ::CvMatND* mat) + { + ::cv::Mat holder = ::cv::cvarrToMat(mat); + ::base64::cvWriteMat_Base64(fs, name, holder); } } diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 1410b26d29..99646e43f0 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -610,9 +610,12 @@ TEST(Core_InputOutput, filestorage_yml_base64) { /* write */ cv::FileStorage fs("test.yml", cv::FileStorage::WRITE); - cv::cvWriteMat_Base64(fs, "normal_2d_mat", _2d_out); - cv::cvWriteMat_Base64(fs, "normal_nd_mat", _nd_out); - cv::cvWriteMat_Base64(fs, "empty_2d_mat", _em_out); + CvMat holder = _2d_out; + cv::cvWriteMat_Base64(*fs, "normal_2d_mat", &holder); + CvMatND holder_nd = _nd_out; + cv::cvWriteMatND_Base64(*fs, "normal_nd_mat", &holder_nd); + holder = _em_out; + cv::cvWriteMat_Base64(*fs, "empty_2d_mat", &holder); fs.release(); } @@ -672,9 +675,12 @@ TEST(Core_InputOutput, filestorage_xml_base64) { /* write */ cv::FileStorage fs("test.xml", cv::FileStorage::WRITE); - cv::cvWriteMat_Base64(fs, "normal_2d_mat", _2d_out); - cv::cvWriteMat_Base64(fs, "normal_nd_mat", _nd_out); - cv::cvWriteMat_Base64(fs, "empty_2d_mat", _em_out); + CvMat holder = _2d_out; + cv::cvWriteMat_Base64(*fs, "normal_2d_mat", &holder); + CvMatND holder_nd = _nd_out; + cv::cvWriteMatND_Base64(*fs, "normal_nd_mat", &holder_nd); + holder = _em_out; + cv::cvWriteMat_Base64(*fs, "empty_2d_mat", &holder); fs.release(); } From 9b959072a20ccf1af8693db04e200f72713f7971 Mon Sep 17 00:00:00 2001 From: Matthew Skolaut Date: Mon, 20 Jun 2016 16:24:15 -0500 Subject: [PATCH 11/30] added python binding for createButton --- modules/python/src2/cv2.cpp | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 3bb98e4f8c..eb0d4c998c 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -1251,6 +1251,7 @@ static void OnChange(int pos, void *param) } #ifdef HAVE_OPENCV_HIGHGUI + static PyObject *pycvCreateTrackbar(PyObject*, PyObject *args) { PyObject *on_change; @@ -1270,6 +1271,55 @@ static PyObject *pycvCreateTrackbar(PyObject*, PyObject *args) } #endif +static void OnButtonChange(int state, void *param) +{ + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + + PyObject *o = (PyObject*)param; + PyObject *args; + if(PyTuple_GetItem(o, 1) != NULL) + { + args = Py_BuildValue("(iO)", state, PyTuple_GetItem(o,1)); + } + else + { + args = Py_BuildValue("(i)", state); + } + + PyObject *r = PyObject_Call(PyTuple_GetItem(o, 0), args, NULL); + if (r == NULL) + PyErr_Print(); + Py_DECREF(args); + PyGILState_Release(gstate); +} + +#ifdef HAVE_OPENCV_HIGHGUI + +static PyObject *pycvCreateButton(PyObject*, PyObject *args, PyObject *kw) +{ + const char* keywords[] = {"buttonName", "onChange", "userData", "buttonType", "initialButtonState", NULL}; + PyObject *on_change; + PyObject *userdata = NULL; + char* button_name; + int button_type = 0; + int initial_button_state = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|Oii", (char**)keywords, &button_name, &on_change, &userdata, &button_type, &initial_button_state)) + return NULL; + if (!PyCallable_Check(on_change)) { + PyErr_SetString(PyExc_TypeError, "onChange must be callable"); + return NULL; + } + if (userdata == NULL) { + userdata = Py_None; + } + + ERRWRAP2(createButton(button_name, OnButtonChange, Py_BuildValue("OO", on_change, userdata), button_type, initial_button_state)); + Py_RETURN_NONE; +} +#endif + /////////////////////////////////////////////////////////////////////////////////////// static int convert_to_char(PyObject *o, char *dst, const char *name = "no_name") @@ -1300,6 +1350,7 @@ static int convert_to_char(PyObject *o, char *dst, const char *name = "no_name") static PyMethodDef special_methods[] = { #ifdef HAVE_OPENCV_HIGHGUI {"createTrackbar", pycvCreateTrackbar, METH_VARARGS, "createTrackbar(trackbarName, windowName, value, count, onChange) -> None"}, + {"createButton", (PyCFunction)pycvCreateButton, METH_VARARGS | METH_KEYWORDS, "createButton(buttonName, onChange [, userData, buttonType, initialButtonState]) -> None"}, {"setMouseCallback", (PyCFunction)pycvSetMouseCallback, METH_VARARGS | METH_KEYWORDS, "setMouseCallback(windowName, onMouse [, param]) -> None"}, #endif {NULL, NULL}, From 7284a77cd35c81947a9ce3c8f95ab4fef4952ae6 Mon Sep 17 00:00:00 2001 From: Matthew Skolaut Date: Mon, 20 Jun 2016 21:07:24 -0500 Subject: [PATCH 12/30] fix casting warning in python createButton binding --- modules/python/src2/cv2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index eb0d4c998c..537e85422b 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -1303,7 +1303,7 @@ static PyObject *pycvCreateButton(PyObject*, PyObject *args, PyObject *kw) PyObject *userdata = NULL; char* button_name; int button_type = 0; - int initial_button_state = 0; + bool initial_button_state = false; if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|Oii", (char**)keywords, &button_name, &on_change, &userdata, &button_type, &initial_button_state)) return NULL; From 33ab236ed3d34284374e8b2741ceedf19664edbf Mon Sep 17 00:00:00 2001 From: Julien Dubiel Date: Tue, 21 Jun 2016 20:00:50 +0200 Subject: [PATCH 13/30] Use CMAKE_LIBRARY_PATH_FLAG variable instead of -L. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11a64080ca..5066246b1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -659,7 +659,7 @@ if(HAVE_CUDA) set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CUDA_cufft_LIBRARY}) endif() foreach(p ${CUDA_LIBS_PATH}) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} -L${p}) + set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${CMAKE_LIBRARY_PATH_FLAG}${p}) endforeach() endif() # ---------------------------------------------------------------------------- From f861d0d64377b76a7ebf7d9369c6d40f706578da Mon Sep 17 00:00:00 2001 From: Matthew Skolaut Date: Tue, 21 Jun 2016 17:16:16 -0500 Subject: [PATCH 14/30] merge #ifs in highgui bindings --- modules/python/src2/cv2.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 537e85422b..4b07e60fa4 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -1251,7 +1251,6 @@ static void OnChange(int pos, void *param) } #ifdef HAVE_OPENCV_HIGHGUI - static PyObject *pycvCreateTrackbar(PyObject*, PyObject *args) { PyObject *on_change; @@ -1269,7 +1268,6 @@ static PyObject *pycvCreateTrackbar(PyObject*, PyObject *args) ERRWRAP2(createTrackbar(trackbar_name, window_name, value, count, OnChange, Py_BuildValue("OO", on_change, Py_None))); Py_RETURN_NONE; } -#endif static void OnButtonChange(int state, void *param) { @@ -1294,8 +1292,6 @@ static void OnButtonChange(int state, void *param) PyGILState_Release(gstate); } -#ifdef HAVE_OPENCV_HIGHGUI - static PyObject *pycvCreateButton(PyObject*, PyObject *args, PyObject *kw) { const char* keywords[] = {"buttonName", "onChange", "userData", "buttonType", "initialButtonState", NULL}; From 7c92ee2e6e758d6454f5cbc13f84f60ceb36a651 Mon Sep 17 00:00:00 2001 From: MYLS Date: Fri, 24 Jun 2016 22:27:42 +0800 Subject: [PATCH 15/30] Split `cvWriteRawData_Base64` into three functions The three new functions: ```cpp void cvStartWriteRawData_Base64(::CvFileStorage * fs, const char* name, int len, const char* dt); void cvWriteRawData_Base64(::CvFileStorage * fs, const void* _data, int len); void cvEndWriteRawData_Base64(::CvFileStorage * fs); ``` Test is also updated. (And it's remarkable that there is a bug in `cvWriteReadData`.) --- .../core/include/opencv2/core/persistence.hpp | 6 +- modules/core/src/persistence.cpp | 154 ++++++++--- modules/core/test/test_io.cpp | 245 +++++++++--------- 3 files changed, 252 insertions(+), 153 deletions(-) diff --git a/modules/core/include/opencv2/core/persistence.hpp b/modules/core/include/opencv2/core/persistence.hpp index 6ceeca438b..65a1ff4c4c 100644 --- a/modules/core/include/opencv2/core/persistence.hpp +++ b/modules/core/include/opencv2/core/persistence.hpp @@ -1241,7 +1241,11 @@ inline String::String(const FileNode& fn): cstr_(0), len_(0) { read(fn, *this, * //! @endcond -CV_EXPORTS void cvWriteRawData_Base64(FileStorage & fs, const void* _data, int len, const char* dt); +CV_EXPORTS void cvStartWriteRawData_Base64(::CvFileStorage * fs, const char* name, int len, const char* dt); + +CV_EXPORTS void cvWriteRawData_Base64(::CvFileStorage * fs, const void* _data, int len); + +CV_EXPORTS void cvEndWriteRawData_Base64(::CvFileStorage * fs); CV_EXPORTS void cvWriteMat_Base64(::CvFileStorage* fs, const char* name, const ::CvMat* mat); diff --git a/modules/core/src/persistence.cpp b/modules/core/src/persistence.cpp index fade7a71a4..2fc4f9f5bb 100644 --- a/modules/core/src/persistence.cpp +++ b/modules/core/src/persistence.cpp @@ -183,6 +183,8 @@ typedef struct CvXMLStackRecord } CvXMLStackRecord; +namespace base64 { class Base64Writer; } + #define CV_XML_OPENING_TAG 1 #define CV_XML_CLOSING_TAG 2 #define CV_XML_EMPTY_TAG 3 @@ -240,6 +242,8 @@ typedef struct CvFileStorage size_t strbufsize, strbufpos; std::deque* outbuf; + base64::Base64Writer * base64_writer; + bool is_opened; } CvFileStorage; @@ -319,6 +323,10 @@ namespace base64 /* sample */ + void cvStartWriteRawData_Base64(::CvFileStorage * fs, const char* name, int len, const char* dt); + void cvWriteRawData_Base64(::CvFileStorage * fs, const void* _data, int len); + void cvEndWriteRawData_Base64(::CvFileStorage * fs); + void cvWriteRawData_Base64(::cv::FileStorage & fs, const void* _data, int len, const char* dt); void cvWriteMat_Base64(CvFileStorage * fs, const char * name, ::cv::Mat const & mat); } @@ -6414,14 +6422,14 @@ public: , binary_buffer(BUFFER_LEN) , base64_buffer(base64_encode_buffer_size(BUFFER_LEN)) , src_beg(0) - , src_end(0) , src_cur(0) + , src_end(0) { src_beg = binary_buffer.data(); src_end = src_beg + BUFFER_LEN; src_cur = src_beg; - // TODO: check if fs.state is valid. + CV_CHECK_OUTPUT_FILE_STORAGE(fs); ::icvFSFlush(file_storage); } @@ -6515,8 +6523,8 @@ private: std::vector binary_buffer; std::vector base64_buffer; uchar * src_beg; - uchar * src_end; uchar * src_cur; + uchar * src_end; }; class base64::MatToBinaryConvertor @@ -6927,9 +6935,72 @@ private: * Wapper ***************************************************************************/ -void base64::make_seq(void * binary, int elem_cnt, const char * dt, CvSeq & seq) +class base64::Base64Writer { - CvFileNode node; +public: + + Base64Writer(::CvFileStorage * fs, const char * name, int len, const char* dt) + : file_storage(fs) + , emitter(fs) + , remaining_data_length(len) + , data_type_string(dt) + { + CV_CHECK_OUTPUT_FILE_STORAGE(fs); + + cvStartWriteStruct(fs, name, CV_NODE_SEQ, "binary"); + icvFSFlush(fs); + + /* output header */ + + /* total byte size(before encode) */ + int size = len * ::icvCalcStructSize(dt, 0); + + std::string buffer = make_base64_header(size, dt); + const uchar * beg = reinterpret_cast(buffer.data()); + const uchar * end = beg + buffer.size(); + + emitter.write(beg, end); + } + + void write(const void* _data, int len) + { + CV_Assert(len >= 0); + CV_Assert(remaining_data_length >= static_cast(len)); + remaining_data_length -= static_cast(len); + + RawDataToBinaryConvertor convertor(_data, len, data_type_string); + emitter.write(convertor); + } + + template inline + void write(_to_binary_convertor_t & convertor, int data_length_of_convertor) + { + CV_Assert(data_length_of_convertor >= 0); + CV_Assert(remaining_data_length >= static_cast(data_length_of_convertor)); + remaining_data_length -= static_cast(data_length_of_convertor); + + emitter.write(convertor); + } + + ~Base64Writer() + { + CV_Assert(remaining_data_length == 0U); + emitter.flush(); + cvEndWriteStruct(file_storage); + icvFSFlush(file_storage); + } + +private: + + ::CvFileStorage * file_storage; + Base64ContextEmitter emitter; + size_t remaining_data_length; + const char* data_type_string; +}; + +void base64::make_seq(void * binary, int elem_cnt, const char * dt, ::CvSeq & seq) +{ + ::CvFileNode node; node.info = 0; BinaryToCvSeqConvertor convertor(binary, elem_cnt, dt); while (convertor) { @@ -6938,7 +7009,32 @@ void base64::make_seq(void * binary, int elem_cnt, const char * dt, CvSeq & seq) } } -void base64::cvWriteRawData_Base64(cv::FileStorage & fs, const void* _data, int len, const char* dt) +void base64::cvStartWriteRawData_Base64(::CvFileStorage * fs, const char* name, int len, const char* dt) +{ + CV_Assert(fs); + CV_CHECK_OUTPUT_FILE_STORAGE(fs); + CV_Assert(fs->base64_writer == 0); + fs->base64_writer = new Base64Writer(fs, name, len, dt); +} + +void base64::cvWriteRawData_Base64(::CvFileStorage * fs, const void* _data, int len) +{ + CV_Assert(fs); + CV_CHECK_OUTPUT_FILE_STORAGE(fs); + CV_Assert(fs->base64_writer != 0); + fs->base64_writer->write(_data, len); +} + +void base64::cvEndWriteRawData_Base64(::CvFileStorage * fs) +{ + CV_Assert(fs); + CV_CHECK_OUTPUT_FILE_STORAGE(fs); + CV_Assert(fs->base64_writer != 0); + delete fs->base64_writer; + fs->base64_writer = 0; +} + +void base64::cvWriteRawData_Base64(::cv::FileStorage & fs, const void* _data, int len, const char* dt) { cvStartWriteStruct(*fs, fs.elname.c_str(), CV_NODE_SEQ, "binary"); { @@ -6960,7 +7056,7 @@ void base64::cvWriteRawData_Base64(cv::FileStorage & fs, const void* _data, int cvEndWriteStruct(*fs); } -void base64::cvWriteMat_Base64(CvFileStorage * fs, const char * name, cv::Mat const & mat) +void base64::cvWriteMat_Base64(::CvFileStorage * fs, const char * name, ::cv::Mat const & mat) { char dt[4]; ::icvEncodeFormat(CV_MAT_TYPE(mat.type()), dt); @@ -6982,27 +7078,14 @@ void base64::cvWriteMat_Base64(CvFileStorage * fs, const char * name, cv::Mat co cvWriteString(fs, "dt", ::icvEncodeFormat(CV_MAT_TYPE(mat.type()), dt ), 0 ); } - cvStartWriteStruct(fs, "data", CV_NODE_SEQ, "binary"); { /* [2]deal with matrix's data */ - Base64ContextEmitter emitter(fs); + int len = static_cast(mat.total()); + MatToBinaryConvertor convertor(mat); - { /* [2][1]define base64 header */ - /* total byte size */ - int size = static_cast(mat.total() * mat.elemSize()); - std::string buffer = make_base64_header(size, dt); - const uchar * beg = reinterpret_cast(buffer.data()); - const uchar * end = beg + buffer.size(); - - emitter.write(beg, end); - } - - { /* [2][2]base64 body */ - MatToBinaryConvertor convertor(mat); - - emitter.write(convertor); - } + cvStartWriteRawData_Base64(fs, "data", len, dt); + fs->base64_writer->write(convertor, len); + cvEndWriteRawData_Base64(fs); } - cvEndWriteStruct(fs); { /* [3]output end */ cvEndWriteStruct(fs); @@ -7015,11 +7098,6 @@ void base64::cvWriteMat_Base64(CvFileStorage * fs, const char * name, cv::Mat co namespace cv { - void cvWriteRawData_Base64(::cv::FileStorage & fs, const void* _data, int len, const char* dt) - { - ::base64::cvWriteRawData_Base64(fs, _data, len, dt); - } - void cvWriteMat_Base64(::CvFileStorage* fs, const char* name, const ::CvMat* mat) { ::cv::Mat holder = ::cv::cvarrToMat(mat); @@ -7031,6 +7109,22 @@ namespace cv ::cv::Mat holder = ::cv::cvarrToMat(mat); ::base64::cvWriteMat_Base64(fs, name, holder); } + + void cvStartWriteRawData_Base64(::CvFileStorage * fs, const char* name, int len, const char* dt) + { + ::base64::cvStartWriteRawData_Base64(fs, name, len, dt); + } + + void cvWriteRawData_Base64(::CvFileStorage * fs, const void* _data, int len) + { + ::base64::cvWriteRawData_Base64(fs, _data, len); + } + + void cvEndWriteRawData_Base64(::CvFileStorage * fs) + { + ::base64::cvEndWriteRawData_Base64(fs); + } + } diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 99646e43f0..39cd2ca176 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -583,132 +583,133 @@ TEST(Core_InputOutput, filestorage_yml_compatibility) //EXPECT_ANY_THROW(); } +class CV_Base64IOTest : public cvtest::BaseTest +{ +private: + std::string file_name; + +public: + CV_Base64IOTest(std::string const & file_name) + : file_name(file_name) {} + ~CV_Base64IOTest() {} +protected: + void run(int) + { + try + { + struct data_t + { + uchar u1, u2; + int i1, i2, i3; + double d1, d2; + int i4; + }; + std::vector rawdata; + + cv::Mat _em_out, _em_in; + cv::Mat _2d_out, _2d_in; + cv::Mat _nd_out, _nd_in; + + { /* init */ + + /* normal mat */ + _2d_out = cv::Mat(100, 100, CV_8UC3, cvScalar(1U, 2U, 127U)); + for (int i = 0; i < _2d_out.rows; ++i) + for (int j = 0; j < _2d_out.cols; ++j) + _2d_out.at(i, j)[1] = i % 256; + + /* 4d mat */ + const int Size[] = {4, 4, 4, 4}; + cv::Mat _4d(4, Size, CV_64FC4, cvScalar(0.888, 0.111, 0.666, 0.444)); + const cv::Range ranges[] = { + cv::Range(0, 2), + cv::Range(0, 2), + cv::Range(1, 2), + cv::Range(0, 2) }; + _nd_out = _4d(ranges); + + /* raw data */ + for (int i = 0; i < 1000; i++) + rawdata.push_back(data_t{1, 2, 1, 2, 3, 0.1, 0.2, i}); + } + + { /* write */ + cv::FileStorage fs(file_name, cv::FileStorage::WRITE); + CvMat holder = _2d_out; + cv::cvWriteMat_Base64(*fs, "normal_2d_mat", &holder); + CvMatND holder_nd = _nd_out; + cv::cvWriteMatND_Base64(*fs, "normal_nd_mat", &holder_nd); + holder = _em_out; + cv::cvWriteMat_Base64(*fs, "empty_2d_mat", &holder); + + cv::cvStartWriteRawData_Base64(*fs, "rawdata", rawdata.size(), "2u3i2di"); + for (int i = 0; i < 10; i++) + cv::cvWriteRawData_Base64(*fs, rawdata.data() + i * 100, 100); + cv::cvEndWriteRawData_Base64(*fs); + + fs.release(); + } + + { /* read */ + cv::FileStorage fs(file_name, cv::FileStorage::READ); + + /* mat */ + fs["empty_2d_mat"] >> _em_in; + fs["normal_2d_mat"] >> _2d_in; + fs["normal_nd_mat"] >> _nd_in; + + /* raw data */ + std::vector(1000).swap(rawdata); + cvReadRawData(*fs, fs["rawdata"].node, rawdata.data(), "2u3i2di"); + + fs.release(); + } + + for (int i = 0; i < 1000; i++) { + // TODO: Solve this bug + //EXPECT_EQ(rawdata[i].u1, 1); + //EXPECT_EQ(rawdata[i].u2, 2); + //EXPECT_EQ(rawdata[i].i1, 1); + //EXPECT_EQ(rawdata[i].i2, 2); + //EXPECT_EQ(rawdata[i].i3, 3); + //EXPECT_EQ(rawdata[i].d1, 0.1); + //EXPECT_EQ(rawdata[i].d2, 0.2); + //EXPECT_EQ(rawdata[i].i4, i); + } + + EXPECT_EQ(_em_in.rows , _em_out.rows); + EXPECT_EQ(_em_in.cols , _em_out.cols); + EXPECT_EQ(_em_in.dims , _em_out.dims); + EXPECT_EQ(_em_in.depth(), _em_out.depth()); + EXPECT_TRUE(_em_in.empty()); + + EXPECT_EQ(_2d_in.rows , _2d_in.rows); + EXPECT_EQ(_2d_in.cols , _2d_in.cols); + EXPECT_EQ(_2d_in.dims , _2d_in.dims); + EXPECT_EQ(_2d_in.depth(), _2d_in.depth()); + for(int i = 0; i < _2d_in.rows; ++i) + for (int j = 0; j < _2d_in.cols; ++j) + EXPECT_EQ(_2d_in.at(i, j), _2d_out.at(i, j)); + + EXPECT_EQ(_nd_in.rows , _nd_in.rows); + EXPECT_EQ(_nd_in.cols , _nd_in.cols); + EXPECT_EQ(_nd_in.dims , _nd_in.dims); + EXPECT_EQ(_nd_in.depth(), _nd_in.depth()); + EXPECT_EQ(cv::countNonZero(cv::mean(_nd_in != _nd_out)), 0); + } + catch(...) + { + ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH); + } + } +}; + TEST(Core_InputOutput, filestorage_yml_base64) { - cv::Mat _em_out, _em_in; - cv::Mat _2d_out, _2d_in; - cv::Mat _nd_out, _nd_in; - - { /* init */ - - /* normal mat */ - _2d_out = cv::Mat(100, 100, CV_8UC3, cvScalar(1U, 2U, 127U)); - for (int i = 0; i < _2d_out.rows; ++i) - for (int j = 0; j < _2d_out.cols; ++j) - _2d_out.at(i, j)[1] = i % 256; - - /* 4d mat */ - const int Size[] = {4, 4, 4, 4}; - cv::Mat _4d(4, Size, CV_64FC4, cvScalar(0.888, 0.111, 0.666, 0.444)); - const cv::Range ranges[] = { - cv::Range(0, 2), - cv::Range(0, 2), - cv::Range(1, 2), - cv::Range(0, 2) }; - _nd_out = _4d(ranges); - } - - { /* write */ - cv::FileStorage fs("test.yml", cv::FileStorage::WRITE); - CvMat holder = _2d_out; - cv::cvWriteMat_Base64(*fs, "normal_2d_mat", &holder); - CvMatND holder_nd = _nd_out; - cv::cvWriteMatND_Base64(*fs, "normal_nd_mat", &holder_nd); - holder = _em_out; - cv::cvWriteMat_Base64(*fs, "empty_2d_mat", &holder); - fs.release(); - } - - { /* read */ - cv::FileStorage fs("test.yml", cv::FileStorage::READ); - fs["empty_2d_mat"] >> _em_in; - fs["normal_2d_mat"] >> _2d_in; - fs["normal_nd_mat"] >> _nd_in; - fs.release(); - } - - EXPECT_EQ(_em_in.rows , _em_out.rows); - EXPECT_EQ(_em_in.cols , _em_out.cols); - EXPECT_EQ(_em_in.dims , _em_out.dims); - EXPECT_EQ(_em_in.depth(), _em_out.depth()); - EXPECT_TRUE(_em_in.empty()); - - EXPECT_EQ(_2d_in.rows , _2d_in.rows); - EXPECT_EQ(_2d_in.cols , _2d_in.cols); - EXPECT_EQ(_2d_in.dims , _2d_in.dims); - EXPECT_EQ(_2d_in.depth(), _2d_in.depth()); - for(int i = 0; i < _2d_in.rows; ++i) - for (int j = 0; j < _2d_in.cols; ++j) - EXPECT_EQ(_2d_in.at(i, j), _2d_out.at(i, j)); - - EXPECT_EQ(_nd_in.rows , _nd_in.rows); - EXPECT_EQ(_nd_in.cols , _nd_in.cols); - EXPECT_EQ(_nd_in.dims , _nd_in.dims); - EXPECT_EQ(_nd_in.depth(), _nd_in.depth()); - EXPECT_EQ(cv::countNonZero(cv::mean(_nd_in != _nd_out)), 0); + CV_Base64IOTest test("base64_test.yml"); test.safe_run(); } TEST(Core_InputOutput, filestorage_xml_base64) { - cv::Mat _em_out, _em_in; - cv::Mat _2d_out, _2d_in; - cv::Mat _nd_out, _nd_in; - - { /* init */ - - /* normal mat */ - _2d_out = cv::Mat(100, 100, CV_8UC3, cvScalar(1U, 2U, 127U)); - for (int i = 0; i < _2d_out.rows; ++i) - for (int j = 0; j < _2d_out.cols; ++j) - _2d_out.at(i, j)[1] = i % 256; - - /* 4d mat */ - const int Size[] = {4, 4, 4, 4}; - cv::Mat _4d(4, Size, CV_64FC4, cvScalar(0.888, 0.111, 0.666, 0.444)); - const cv::Range ranges[] = { - cv::Range(0, 2), - cv::Range(0, 2), - cv::Range(1, 2), - cv::Range(0, 2) }; - _nd_out = _4d(ranges); - } - - { /* write */ - cv::FileStorage fs("test.xml", cv::FileStorage::WRITE); - CvMat holder = _2d_out; - cv::cvWriteMat_Base64(*fs, "normal_2d_mat", &holder); - CvMatND holder_nd = _nd_out; - cv::cvWriteMatND_Base64(*fs, "normal_nd_mat", &holder_nd); - holder = _em_out; - cv::cvWriteMat_Base64(*fs, "empty_2d_mat", &holder); - fs.release(); - } - - { /* read */ - cv::FileStorage fs("test.xml", cv::FileStorage::READ); - fs["empty_2d_mat"] >> _em_in; - fs["normal_2d_mat"] >> _2d_in; - fs["normal_nd_mat"] >> _nd_in; - fs.release(); - } - - EXPECT_EQ(_em_in.rows , _em_out.rows); - EXPECT_EQ(_em_in.cols , _em_out.cols); - EXPECT_EQ(_em_in.dims , _em_out.dims); - EXPECT_EQ(_em_in.depth(), _em_out.depth()); - EXPECT_TRUE(_em_in.empty()); - - EXPECT_EQ(_2d_in.rows , _2d_in.rows); - EXPECT_EQ(_2d_in.cols , _2d_in.cols); - EXPECT_EQ(_2d_in.dims , _2d_in.dims); - EXPECT_EQ(_2d_in.depth(), _2d_in.depth()); - for(int i = 0; i < _2d_in.rows; ++i) - for (int j = 0; j < _2d_in.cols; ++j) - EXPECT_EQ(_2d_in.at(i, j), _2d_out.at(i, j)); - - EXPECT_EQ(_nd_in.rows , _nd_in.rows); - EXPECT_EQ(_nd_in.cols , _nd_in.cols); - EXPECT_EQ(_nd_in.dims , _nd_in.dims); - EXPECT_EQ(_nd_in.depth(), _nd_in.depth()); - EXPECT_EQ(cv::countNonZero(cv::sum(_nd_in != _nd_out)), 0); + CV_Base64IOTest test("base64_test.xml"); test.safe_run(); } From 959002fb96cea52b71454229e01d775fbd4c0896 Mon Sep 17 00:00:00 2001 From: MYLS Date: Fri, 24 Jun 2016 23:41:40 +0800 Subject: [PATCH 16/30] solve warnings and errors in test. --- modules/core/test/test_io.cpp | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 39cd2ca176..3376965c2a 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -588,22 +588,23 @@ class CV_Base64IOTest : public cvtest::BaseTest private: std::string file_name; + struct data_t + { + uchar u1, u2; + int i1, i2, i3; + double d1, d2; + int i4; + }; + public: - CV_Base64IOTest(std::string const & file_name) - : file_name(file_name) {} + CV_Base64IOTest(std::string const & test_file_name) + : file_name(test_file_name) {} ~CV_Base64IOTest() {} protected: void run(int) { try { - struct data_t - { - uchar u1, u2; - int i1, i2, i3; - double d1, d2; - int i4; - }; std::vector rawdata; cv::Mat _em_out, _em_in; @@ -629,8 +630,18 @@ protected: _nd_out = _4d(ranges); /* raw data */ - for (int i = 0; i < 1000; i++) - rawdata.push_back(data_t{1, 2, 1, 2, 3, 0.1, 0.2, i}); + for (int i = 0; i < 1000; i++) { + data_t tmp; + rawdata[i].u1 = 1; + rawdata[i].u2 = 2; + rawdata[i].i1 = 1; + rawdata[i].i2 = 2; + rawdata[i].i3 = 3; + rawdata[i].d1 = 0.1; + rawdata[i].d2 = 0.2; + rawdata[i].i4 = i; + rawdata.push_back(tmp); + } } { /* write */ @@ -642,7 +653,7 @@ protected: holder = _em_out; cv::cvWriteMat_Base64(*fs, "empty_2d_mat", &holder); - cv::cvStartWriteRawData_Base64(*fs, "rawdata", rawdata.size(), "2u3i2di"); + cv::cvStartWriteRawData_Base64(*fs, "rawdata", static_cast(rawdata.size()), "2u3i2di"); for (int i = 0; i < 10; i++) cv::cvWriteRawData_Base64(*fs, rawdata.data() + i * 100, 100); cv::cvEndWriteRawData_Base64(*fs); From 677d4d20ce9de6b548887a05bbdd0ffb207281b0 Mon Sep 17 00:00:00 2001 From: MYLS Date: Sat, 25 Jun 2016 00:37:13 +0800 Subject: [PATCH 17/30] fixed an error in the test... --- modules/core/test/test_io.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 3376965c2a..dcb25d72e0 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -632,14 +632,14 @@ protected: /* raw data */ for (int i = 0; i < 1000; i++) { data_t tmp; - rawdata[i].u1 = 1; - rawdata[i].u2 = 2; - rawdata[i].i1 = 1; - rawdata[i].i2 = 2; - rawdata[i].i3 = 3; - rawdata[i].d1 = 0.1; - rawdata[i].d2 = 0.2; - rawdata[i].i4 = i; + tmp.u1 = 1; + tmp.u2 = 2; + tmp.i1 = 1; + tmp.i2 = 2; + tmp.i3 = 3; + tmp.d1 = 0.1; + tmp.d2 = 0.2; + tmp.i4 = i; rawdata.push_back(tmp); } } From df5a7c8ee9d877655a6981dd263c0f303e239b51 Mon Sep 17 00:00:00 2001 From: MYLS Date: Sat, 25 Jun 2016 02:24:33 +0800 Subject: [PATCH 18/30] build again for OpenCL. I could not find the cause of the error: ``` C:\builds_ocv\precommit_opencl\opencv\modules\ts\src\ts_perf.cpp(361): error: The difference between expect_max and actual_max is 8445966.0000002384, which exceeds eps, where expect_max evaluates to 0.9999997615814209, actual_max evaluates to 8445967, and eps evaluates to 1.0000000000000001e-005. Argument "dst0" has unexpected maximal value ``` Hope this is a false alarm. --- modules/core/test/test_io.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index dcb25d72e0..1367776f2d 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -580,7 +580,7 @@ TEST(Core_InputOutput, FileStorageKey) TEST(Core_InputOutput, filestorage_yml_compatibility) { - //EXPECT_ANY_THROW(); + // TODO: } class CV_Base64IOTest : public cvtest::BaseTest @@ -617,7 +617,7 @@ protected: _2d_out = cv::Mat(100, 100, CV_8UC3, cvScalar(1U, 2U, 127U)); for (int i = 0; i < _2d_out.rows; ++i) for (int j = 0; j < _2d_out.cols; ++j) - _2d_out.at(i, j)[1] = i % 256; + _2d_out.at(i, j)[1] = (i + j) % 256; /* 4d mat */ const int Size[] = {4, 4, 4, 4}; @@ -677,7 +677,7 @@ protected: } for (int i = 0; i < 1000; i++) { - // TODO: Solve this bug + // TODO: Solve this bug in `cvReadRawData` //EXPECT_EQ(rawdata[i].u1, 1); //EXPECT_EQ(rawdata[i].u2, 2); //EXPECT_EQ(rawdata[i].i1, 1); @@ -717,10 +717,10 @@ protected: TEST(Core_InputOutput, filestorage_yml_base64) { - CV_Base64IOTest test("base64_test.yml"); test.safe_run(); + CV_Base64IOTest test("base64_test_tmp_file.yml"); test.safe_run(); } TEST(Core_InputOutput, filestorage_xml_base64) { - CV_Base64IOTest test("base64_test.xml"); test.safe_run(); + CV_Base64IOTest test("base64_test_tmp_file.xml"); test.safe_run(); } From 1b22783d4636a74512171d67b95e6482f73cd897 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Sun, 26 Jun 2016 16:39:19 +0300 Subject: [PATCH 19/30] Update grfmt_png.cpp --- modules/imgcodecs/src/grfmt_png.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/imgcodecs/src/grfmt_png.cpp b/modules/imgcodecs/src/grfmt_png.cpp index d5d175f89e..e672e0cc96 100644 --- a/modules/imgcodecs/src/grfmt_png.cpp +++ b/modules/imgcodecs/src/grfmt_png.cpp @@ -370,22 +370,23 @@ bool PngEncoder::write( const Mat& img, const std::vector& params ) } int compression_level = -1; // Invalid value to allow setting 0-9 as valid - int compression_strategy = Z_RLE; // Default strategy + int compression_strategy = IMWRITE_PNG_STRATEGY_RLE; // Default strategy bool isBilevel = false; for( size_t i = 0; i < params.size(); i += 2 ) { - if( params[i] == CV_IMWRITE_PNG_COMPRESSION ) + if( params[i] == IMWRITE_PNG_COMPRESSION ) { + compression_strategy = IMWRITE_PNG_STRATEGY_DEFAULT; // Default strategy compression_level = params[i+1]; compression_level = MIN(MAX(compression_level, 0), Z_BEST_COMPRESSION); } - if( params[i] == CV_IMWRITE_PNG_STRATEGY ) + if( params[i] == IMWRITE_PNG_STRATEGY ) { compression_strategy = params[i+1]; compression_strategy = MIN(MAX(compression_strategy, 0), Z_FIXED); } - if( params[i] == CV_IMWRITE_PNG_BILEVEL ) + if( params[i] == IMWRITE_PNG_BILEVEL ) { isBilevel = params[i+1] != 0; } From 11ca1c95f8ee86a0f38e48c19605b8f0f4791924 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Mon, 15 Feb 2016 15:37:29 +0200 Subject: [PATCH 20/30] update cpp samples and tutorials --- .../jni/DetectionBasedTracker_jni.cpp | 2 +- .../jni/jni_part.cpp | 6 +- samples/cpp/3calibration.cpp | 8 +- samples/cpp/contours2.cpp | 4 +- samples/cpp/convexhull.cpp | 5 +- samples/cpp/cout_mat.cpp | 2 +- samples/cpp/dbt_face_detection.cpp | 12 +-- samples/cpp/delaunay2.cpp | 4 +- samples/cpp/facedetect.cpp | 6 +- samples/cpp/facial_features.cpp | 6 +- samples/cpp/fback.cpp | 6 +- samples/cpp/ffilldemo.cpp | 6 +- samples/cpp/filestorage.cpp | 2 +- samples/cpp/fitellipse.cpp | 5 +- samples/cpp/grabcut.cpp | 4 +- samples/cpp/houghcircles.cpp | 4 +- samples/cpp/houghlines.cpp | 4 +- samples/cpp/image.cpp | 4 +- samples/cpp/image_sequence.cpp | 6 +- samples/cpp/imagelist_creator.cpp | 4 +- samples/cpp/inpaint.cpp | 6 +- samples/cpp/intelperc_capture.cpp | 4 +- samples/cpp/kalman.cpp | 2 +- samples/cpp/laplace.cpp | 6 +- samples/cpp/letter_recog.cpp | 4 +- samples/cpp/lkdemo.cpp | 6 +- samples/cpp/lsd_lines.cpp | 10 +- samples/cpp/minarea.cpp | 4 +- samples/cpp/morphology2.cpp | 6 +- samples/cpp/openni_capture.cpp | 4 +- samples/cpp/pca.cpp | 4 +- samples/cpp/phase_corr.cpp | 8 +- samples/cpp/polar_transforms.cpp | 95 ++++++++----------- samples/cpp/segment_objects.cpp | 6 +- samples/cpp/squares.cpp | 19 ++-- samples/cpp/starter_imagelist.cpp | 2 +- samples/cpp/starter_video.cpp | 4 +- samples/cpp/stereo_calib.cpp | 6 +- samples/cpp/stereo_match.cpp | 4 +- samples/cpp/tree_engine.cpp | 4 +- .../HighGUI/AddingImagesTrackbar.cpp | 2 +- .../HighGUI/BasicLinearTransformsTrackbar.cpp | 2 +- .../Histograms_Matching/EqualizeHist_Demo.cpp | 9 +- .../MatchTemplate_Demo.cpp | 24 +++-- .../calcBackProject_Demo1.cpp | 12 ++- .../calcBackProject_Demo2.cpp | 6 +- .../Histograms_Matching/calcHist_Demo.cpp | 16 +++- .../Histograms_Matching/compareHist_Demo.cpp | 19 ++-- .../tutorial_code/ImgProc/AddingImages.cpp | 2 +- .../ImgProc/BasicLinearTransforms.cpp | 2 +- .../tutorial_code/ImgProc/Morphology_1.cpp | 8 +- .../tutorial_code/ImgProc/Morphology_2.cpp | 9 +- .../cpp/tutorial_code/ImgProc/Pyramids.cpp | 7 +- .../cpp/tutorial_code/ImgProc/Smoothing.cpp | 9 +- .../cpp/tutorial_code/ImgProc/Threshold.cpp | 13 +-- .../ImgTrans/CannyDetector_Demo.cpp | 8 +- .../ImgTrans/Geometric_Transforms_Demo.cpp | 7 +- .../ImgTrans/HoughCircle_Demo.cpp | 6 +- .../ImgTrans/HoughLines_Demo.cpp | 7 +- .../tutorial_code/ImgTrans/Laplace_Demo.cpp | 8 +- .../cpp/tutorial_code/ImgTrans/Remap_Demo.cpp | 7 +- .../cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp | 8 +- .../ImgTrans/copyMakeBorder_demo.cpp | 8 +- .../tutorial_code/ImgTrans/filter2D_demo.cpp | 8 +- .../ShapeDescriptors/findContours_demo.cpp | 8 +- .../generalContours_demo1.cpp | 8 +- .../generalContours_demo2.cpp | 8 +- .../ShapeDescriptors/hull_demo.cpp | 8 +- .../ShapeDescriptors/moments_demo.cpp | 8 +- .../pointPolygonTest_demo.cpp | 6 +- .../TrackingMotion/cornerDetector_Demo.cpp | 9 +- .../TrackingMotion/cornerHarris_Demo.cpp | 8 +- .../TrackingMotion/cornerSubPix_Demo.cpp | 8 +- .../goodFeaturesToTrack_Demo.cpp | 8 +- .../camera_calibration/camera_calibration.cpp | 4 +- .../real_time_pose_estimation/src/Utils.cpp | 4 +- .../src/main_detection.cpp | 8 +- .../src/main_registration.cpp | 8 +- .../calib3d/stereoBM/SBM_Sample.cpp | 6 +- .../discrete_fourier_transform.cpp | 6 +- .../file_input_output/file_input_output.cpp | 2 +- .../how_to_scan_images/how_to_scan_images.cpp | 2 +- .../interoperability_with_OpenCV_1.cpp | 7 +- .../mat_mask_operations.cpp | 30 +++--- .../mat_the_basic_image_container.cpp | 4 +- .../imgcodecs/GDAL_IO/gdal-image.cpp | 10 +- .../display_image/display_image.cpp | 8 +- .../photo/decolorization/decolor.cpp | 10 +- .../non_photorealistic_rendering/npr_demo.cpp | 12 +-- samples/cpp/tutorial_code/video/bg_sub.cpp | 6 +- .../video-input-psnr-ssim.cpp | 10 +- .../videoio/video-write/video-write.cpp | 6 +- samples/gpu/alpha_comp.cpp | 2 +- samples/gpu/cascadeclassifier.cpp | 6 +- samples/gpu/driver_api_multi.cpp | 2 +- samples/gpu/driver_api_stereo_multi.cpp | 4 +- samples/gpu/multi.cpp | 2 +- samples/gpu/opengl.cpp | 4 +- samples/gpu/opticalflow_nvidia_api.cpp | 3 +- samples/gpu/surf_keypoint_matcher.cpp | 6 +- samples/tapi/camshift.cpp | 6 +- samples/tapi/clahe.cpp | 6 +- samples/tapi/squares.cpp | 4 +- samples/tapi/tvl1_optical_flow.cpp | 4 +- .../FaceDetection/MainPage.xaml.cpp | 8 +- .../OcvTransform/OcvTransform.cpp | 6 +- .../OcvImageProcessing/MainPage.xaml.cpp | 4 +- .../PhoneTutorial/MainPage.xaml.cpp | 4 +- .../Direct3DInterop.cpp | 6 +- .../OpenCVComponent/OpenCVComponent.cpp | 7 +- 110 files changed, 394 insertions(+), 423 deletions(-) diff --git a/samples/android/face-detection/jni/DetectionBasedTracker_jni.cpp b/samples/android/face-detection/jni/DetectionBasedTracker_jni.cpp index 9fd8494b2f..7d198dc53e 100644 --- a/samples/android/face-detection/jni/DetectionBasedTracker_jni.cpp +++ b/samples/android/face-detection/jni/DetectionBasedTracker_jni.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/samples/android/tutorial-2-mixedprocessing/jni/jni_part.cpp b/samples/android/tutorial-2-mixedprocessing/jni/jni_part.cpp index 2c09961563..72fa0b24ab 100644 --- a/samples/android/tutorial-2-mixedprocessing/jni/jni_part.cpp +++ b/samples/android/tutorial-2-mixedprocessing/jni/jni_part.cpp @@ -1,7 +1,7 @@ #include -#include -#include -#include +#include +#include +#include #include using namespace std; diff --git a/samples/cpp/3calibration.cpp b/samples/cpp/3calibration.cpp index 12f2c81fca..7079b6d062 100644 --- a/samples/cpp/3calibration.cpp +++ b/samples/cpp/3calibration.cpp @@ -2,10 +2,10 @@ * 3calibration.cpp -- Calibrate 3 cameras in a horizontal line together. */ -#include "opencv2/calib3d/calib3d.hpp" -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/imgcodecs/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/calib3d.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/imgcodecs.hpp" +#include "opencv2/highgui.hpp" #include "opencv2/core/utility.hpp" #include diff --git a/samples/cpp/contours2.cpp b/samples/cpp/contours2.cpp index c5a1fa70f5..437f76cb24 100644 --- a/samples/cpp/contours2.cpp +++ b/samples/cpp/contours2.cpp @@ -1,5 +1,5 @@ -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/highgui.hpp" #include #include diff --git a/samples/cpp/convexhull.cpp b/samples/cpp/convexhull.cpp index 36e5544548..fd2275645d 100644 --- a/samples/cpp/convexhull.cpp +++ b/samples/cpp/convexhull.cpp @@ -1,6 +1,5 @@ -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/highgui/highgui.hpp" -#include +#include "opencv2/imgproc.hpp" +#include "opencv2/highgui.hpp" #include using namespace cv; diff --git a/samples/cpp/cout_mat.cpp b/samples/cpp/cout_mat.cpp index bf1dfb2a41..ed2cd71c86 100644 --- a/samples/cpp/cout_mat.cpp +++ b/samples/cpp/cout_mat.cpp @@ -5,7 +5,7 @@ * */ -#include "opencv2/core/core.hpp" +#include "opencv2/core.hpp" #include using namespace std; diff --git a/samples/cpp/dbt_face_detection.cpp b/samples/cpp/dbt_face_detection.cpp index d7409bf5b5..920ae001d8 100644 --- a/samples/cpp/dbt_face_detection.cpp +++ b/samples/cpp/dbt_face_detection.cpp @@ -1,11 +1,11 @@ #if defined(__linux__) || defined(LINUX) || defined(__APPLE__) || defined(ANDROID) -#include // Gaussian Blur -#include // Basic OpenCV structures (cv::Mat, Scalar) -#include -#include // OpenCV window I/O -#include -#include +#include // Gaussian Blur +#include // Basic OpenCV structures (cv::Mat, Scalar) +#include +#include // OpenCV window I/O +#include +#include #include #include diff --git a/samples/cpp/delaunay2.cpp b/samples/cpp/delaunay2.cpp index a370feb2a7..4807cd373f 100644 --- a/samples/cpp/delaunay2.cpp +++ b/samples/cpp/delaunay2.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include using namespace cv; diff --git a/samples/cpp/facedetect.cpp b/samples/cpp/facedetect.cpp index 39717b7336..e9b648a7e9 100644 --- a/samples/cpp/facedetect.cpp +++ b/samples/cpp/facedetect.cpp @@ -177,7 +177,7 @@ void detectAndDraw( Mat& img, CascadeClassifier& cascade, resize( gray, smallImg, Size(), fx, fx, INTER_LINEAR ); equalizeHist( smallImg, smallImg ); - t = (double)cvGetTickCount(); + t = (double)getTickCount(); cascade.detectMultiScale( smallImg, faces, 1.1, 2, 0 //|CASCADE_FIND_BIGGEST_OBJECT @@ -198,8 +198,8 @@ void detectAndDraw( Mat& img, CascadeClassifier& cascade, faces.push_back(Rect(smallImg.cols - r->x - r->width, r->y, r->width, r->height)); } } - t = (double)cvGetTickCount() - t; - printf( "detection time = %g ms\n", t/((double)cvGetTickFrequency()*1000.) ); + t = (double)getTickCount() - t; + printf( "detection time = %g ms\n", t*1000/getTickFrequency()); for ( size_t i = 0; i < faces.size(); i++ ) { Rect r = faces[i]; diff --git a/samples/cpp/facial_features.cpp b/samples/cpp/facial_features.cpp index f46fa3fb56..3ed6a442f9 100644 --- a/samples/cpp/facial_features.cpp +++ b/samples/cpp/facial_features.cpp @@ -6,9 +6,9 @@ * */ -#include "opencv2/objdetect/objdetect.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/objdetect.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include #include diff --git a/samples/cpp/fback.cpp b/samples/cpp/fback.cpp index 5fbec6913c..a044844023 100644 --- a/samples/cpp/fback.cpp +++ b/samples/cpp/fback.cpp @@ -1,7 +1,7 @@ #include "opencv2/video/tracking.hpp" -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/videoio/videoio.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/videoio.hpp" +#include "opencv2/highgui.hpp" #include diff --git a/samples/cpp/ffilldemo.cpp b/samples/cpp/ffilldemo.cpp index 93bdd672bd..d10d72e0eb 100644 --- a/samples/cpp/ffilldemo.cpp +++ b/samples/cpp/ffilldemo.cpp @@ -1,7 +1,7 @@ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/videoio/videoio.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/videoio.hpp" +#include "opencv2/highgui.hpp" #include diff --git a/samples/cpp/filestorage.cpp b/samples/cpp/filestorage.cpp index 60ea51acab..46b4da2414 100644 --- a/samples/cpp/filestorage.cpp +++ b/samples/cpp/filestorage.cpp @@ -2,7 +2,7 @@ * filestorage_sample demonstrate the usage of the opencv serialization functionality */ -#include "opencv2/core/core.hpp" +#include "opencv2/core.hpp" #include #include diff --git a/samples/cpp/fitellipse.cpp b/samples/cpp/fitellipse.cpp index b83f617c1d..0cd6c4a6db 100644 --- a/samples/cpp/fitellipse.cpp +++ b/samples/cpp/fitellipse.cpp @@ -14,10 +14,11 @@ * * ********************************************************************************/ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include + using namespace cv; using namespace std; diff --git a/samples/cpp/grabcut.cpp b/samples/cpp/grabcut.cpp index b6b406000b..726906c6ff 100644 --- a/samples/cpp/grabcut.cpp +++ b/samples/cpp/grabcut.cpp @@ -1,6 +1,6 @@ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include diff --git a/samples/cpp/houghcircles.cpp b/samples/cpp/houghcircles.cpp index bdafffec30..26c4dbae08 100644 --- a/samples/cpp/houghcircles.cpp +++ b/samples/cpp/houghcircles.cpp @@ -1,6 +1,6 @@ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include diff --git a/samples/cpp/houghlines.cpp b/samples/cpp/houghlines.cpp index ddeb3bd751..94eec86eeb 100644 --- a/samples/cpp/houghlines.cpp +++ b/samples/cpp/houghlines.cpp @@ -1,6 +1,6 @@ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include diff --git a/samples/cpp/image.cpp b/samples/cpp/image.cpp index b5925c69af..fc57738a77 100644 --- a/samples/cpp/image.cpp +++ b/samples/cpp/image.cpp @@ -1,7 +1,7 @@ #include #include -#include -#include +#include +#include #include using namespace cv; // all the new API is put into "cv" namespace. Export its content diff --git a/samples/cpp/image_sequence.cpp b/samples/cpp/image_sequence.cpp index 14b63e39c4..6a84fab4bd 100644 --- a/samples/cpp/image_sequence.cpp +++ b/samples/cpp/image_sequence.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include diff --git a/samples/cpp/imagelist_creator.cpp b/samples/cpp/imagelist_creator.cpp index bdb023187b..5b2dc38d47 100644 --- a/samples/cpp/imagelist_creator.cpp +++ b/samples/cpp/imagelist_creator.cpp @@ -1,9 +1,9 @@ /*this creates a yaml or xml list of files from the command line args */ -#include "opencv2/core/core.hpp" +#include "opencv2/core.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include #include diff --git a/samples/cpp/inpaint.cpp b/samples/cpp/inpaint.cpp index 62d7521932..86e6e37416 100644 --- a/samples/cpp/inpaint.cpp +++ b/samples/cpp/inpaint.cpp @@ -1,7 +1,7 @@ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/photo/photo.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/photo.hpp" #include diff --git a/samples/cpp/intelperc_capture.cpp b/samples/cpp/intelperc_capture.cpp index daae4420fb..d8a1c32241 100644 --- a/samples/cpp/intelperc_capture.cpp +++ b/samples/cpp/intelperc_capture.cpp @@ -1,8 +1,8 @@ // testOpenCVCam.cpp : Defines the entry point for the console application. // -#include "opencv2/videoio/videoio.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/videoio.hpp" +#include "opencv2/highgui.hpp" #include diff --git a/samples/cpp/kalman.cpp b/samples/cpp/kalman.cpp index 8f9adc6c27..501a749124 100644 --- a/samples/cpp/kalman.cpp +++ b/samples/cpp/kalman.cpp @@ -1,5 +1,5 @@ #include "opencv2/video/tracking.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include diff --git a/samples/cpp/laplace.cpp b/samples/cpp/laplace.cpp index b33b49cbdb..462f62804e 100644 --- a/samples/cpp/laplace.cpp +++ b/samples/cpp/laplace.cpp @@ -1,6 +1,6 @@ -#include "opencv2/videoio/videoio.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/videoio.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include #include diff --git a/samples/cpp/letter_recog.cpp b/samples/cpp/letter_recog.cpp index 3d7e34ab7a..0eb67d1e42 100644 --- a/samples/cpp/letter_recog.cpp +++ b/samples/cpp/letter_recog.cpp @@ -1,5 +1,5 @@ -#include "opencv2/core/core.hpp" -#include "opencv2/ml/ml.hpp" +#include "opencv2/core.hpp" +#include "opencv2/ml.hpp" #include #include diff --git a/samples/cpp/lkdemo.cpp b/samples/cpp/lkdemo.cpp index 3881aa8650..5e57aa84a4 100644 --- a/samples/cpp/lkdemo.cpp +++ b/samples/cpp/lkdemo.cpp @@ -1,7 +1,7 @@ #include "opencv2/video/tracking.hpp" -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/videoio/videoio.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/videoio.hpp" +#include "opencv2/highgui.hpp" #include #include diff --git a/samples/cpp/lsd_lines.cpp b/samples/cpp/lsd_lines.cpp index 4c8c7e0a41..e0db6c3669 100644 --- a/samples/cpp/lsd_lines.cpp +++ b/samples/cpp/lsd_lines.cpp @@ -1,11 +1,8 @@ #include -#include -#include "opencv2/core/core.hpp" -#include "opencv2/core/utility.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" using namespace std; using namespace cv; @@ -23,6 +20,9 @@ int main(int argc, char** argv) Mat image = imread(in, IMREAD_GRAYSCALE); + if( image.empty() ) + { return -1; } + #if 0 Canny(image, image, 50, 200, 3); // Apply canny edge #endif diff --git a/samples/cpp/minarea.cpp b/samples/cpp/minarea.cpp index 91ad5a37bf..ac79db5e5a 100644 --- a/samples/cpp/minarea.cpp +++ b/samples/cpp/minarea.cpp @@ -1,5 +1,5 @@ -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include diff --git a/samples/cpp/morphology2.cpp b/samples/cpp/morphology2.cpp index 04e916c64a..8439080b2b 100644 --- a/samples/cpp/morphology2.cpp +++ b/samples/cpp/morphology2.cpp @@ -1,6 +1,6 @@ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include #include #include @@ -66,7 +66,7 @@ int main( int argc, char** argv ) return 0; } std::string filename = parser.get("@image"); - if( (src = imread(filename,1)).empty() ) + if( (src = imread(filename,IMREAD_COLOR)).empty() ) { help(); return -1; diff --git a/samples/cpp/openni_capture.cpp b/samples/cpp/openni_capture.cpp index 70d4a7c610..6c51624977 100644 --- a/samples/cpp/openni_capture.cpp +++ b/samples/cpp/openni_capture.cpp @@ -1,6 +1,6 @@ #include "opencv2/videoio/videoio.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include diff --git a/samples/cpp/pca.cpp b/samples/cpp/pca.cpp index 35fd0c1a04..b33a463211 100644 --- a/samples/cpp/pca.cpp +++ b/samples/cpp/pca.cpp @@ -42,9 +42,9 @@ #include #include -#include +#include #include "opencv2/imgcodecs.hpp" -#include +#include using namespace cv; using namespace std; diff --git a/samples/cpp/phase_corr.cpp b/samples/cpp/phase_corr.cpp index 5e8685fcfa..c3120fe084 100644 --- a/samples/cpp/phase_corr.cpp +++ b/samples/cpp/phase_corr.cpp @@ -1,7 +1,7 @@ -#include "opencv2/core/core.hpp" -#include "opencv2/videoio/videoio.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/core.hpp" +#include "opencv2/videoio.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" using namespace cv; diff --git a/samples/cpp/polar_transforms.cpp b/samples/cpp/polar_transforms.cpp index 872dda8c3f..3cbc431c3c 100644 --- a/samples/cpp/polar_transforms.cpp +++ b/samples/cpp/polar_transforms.cpp @@ -1,94 +1,75 @@ -#include "opencv2/imgproc/imgproc_c.h" -#include "opencv2/videoio/videoio_c.h" -#include "opencv2/highgui/highgui_c.h" -#include "opencv2/core/utility.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include -#include -#include +using namespace cv; static void help( void ) { printf("\nThis program illustrates Linear-Polar and Log-Polar image transforms\n" "Usage :\n" - "./polar_transforms [[camera number -- Default 0],[AVI path_filename]]\n\n" - ); + "./polar_transforms [[camera number -- Default 0],[path_to_filename]]\n\n"); } + int main( int argc, char** argv ) { - CvCapture* capture = 0; - IplImage* log_polar_img = 0; - IplImage* lin_polar_img = 0; - IplImage* recovered_img = 0; + VideoCapture capture; + Mat log_polar_img, lin_polar_img, recovered_log_polar, recovered_lin_polar_img; help(); - cv::CommandLineParser parser(argc, argv, "{help h||}{@input|0|}"); - if (parser.has("help")) - { - help(); - return 0; - } + + CommandLineParser parser(argc, argv, "{@input|0|}"); std::string arg = parser.get("@input"); + if( arg.size() == 1 && isdigit(arg[0]) ) - capture = cvCaptureFromCAM( arg[0] - '0' ); + capture.open( arg[0] - '0' ); else - capture = cvCaptureFromAVI( arg.c_str() ); - if( !capture ) + capture.open( arg.c_str() ); + + if( !capture.isOpened() ) { const char* name = argv[0]; fprintf(stderr,"Could not initialize capturing...\n"); fprintf(stderr,"Usage: %s , or \n %s \n", name, name); - help(); return -1; } - cvNamedWindow( "Linear-Polar", 0 ); - cvNamedWindow( "Log-Polar", 0 ); - cvNamedWindow( "Recovered image", 0 ); + namedWindow( "Linear-Polar", WINDOW_NORMAL ); + namedWindow( "Log-Polar", WINDOW_NORMAL ); + namedWindow( "Recovered Linear-Polar", WINDOW_NORMAL ); + namedWindow( "Recovered Log-Polar", WINDOW_NORMAL ); - cvMoveWindow( "Linear-Polar", 20,20 ); - cvMoveWindow( "Log-Polar", 700,20 ); - cvMoveWindow( "Recovered image", 20,700 ); + moveWindow( "Linear-Polar", 20,20 ); + moveWindow( "Log-Polar", 700,20 ); + moveWindow( "Recovered Linear-Polar", 20, 350 ); + moveWindow( "Recovered Log-Polar", 700, 350 ); for(;;) { - IplImage* frame = 0; + Mat frame; + capture >> frame; - frame = cvQueryFrame( capture ); - if( !frame ) + if( frame.empty() ) break; - if( !log_polar_img ) - { - log_polar_img = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels ); - lin_polar_img = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels ); - recovered_img = cvCreateImage( cvSize(frame->width,frame->height), IPL_DEPTH_8U, frame->nChannels ); - } + Point2f center( (float)frame.cols / 2, (float)frame.rows / 2 ); + double M = (double)frame.cols / 8; - cvLogPolar(frame,log_polar_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS); - cvLinearPolar(frame,lin_polar_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS); + logPolar(frame,log_polar_img, center, M, INTER_LINEAR + WARP_FILL_OUTLIERS); + linearPolar(frame,lin_polar_img, center, M, INTER_LINEAR + WARP_FILL_OUTLIERS); -#if 0 - cvLogPolar(log_polar_img,recovered_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_WARP_INVERSE_MAP+CV_INTER_LINEAR); -#else - cvLinearPolar(lin_polar_img,recovered_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_WARP_INVERSE_MAP+CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS); -#endif + logPolar(log_polar_img, recovered_log_polar, center, M, WARP_INVERSE_MAP + INTER_LINEAR); + linearPolar(lin_polar_img, recovered_lin_polar_img, center, M, WARP_INVERSE_MAP + INTER_LINEAR + WARP_FILL_OUTLIERS); - cvShowImage("Log-Polar", log_polar_img ); - cvShowImage("Linear-Polar", lin_polar_img ); - cvShowImage("Recovered image", recovered_img ); + imshow("Log-Polar", log_polar_img ); + imshow("Linear-Polar", lin_polar_img ); + imshow("Recovered Linear-Polar", recovered_lin_polar_img ); + imshow("Recovered Log-Polar", recovered_log_polar ); - if( cvWaitKey(10) >= 0 ) + if( waitKey(10) >= 0 ) break; } - cvReleaseCapture( &capture ); - cvDestroyWindow("Linear-Polar"); - cvDestroyWindow("Log-Polar"); - cvDestroyWindow("Recovered image"); - + waitKey(0); return 0; } - -#ifdef _EiC -main(1,"laplace.c"); -#endif diff --git a/samples/cpp/segment_objects.cpp b/samples/cpp/segment_objects.cpp index 3c217f679d..916283124f 100644 --- a/samples/cpp/segment_objects.cpp +++ b/samples/cpp/segment_objects.cpp @@ -1,6 +1,6 @@ -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/videoio/videoio.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/videoio.hpp" +#include "opencv2/highgui.hpp" #include "opencv2/video/background_segm.hpp" #include #include diff --git a/samples/cpp/squares.cpp b/samples/cpp/squares.cpp index f53e931e75..df8459caa4 100644 --- a/samples/cpp/squares.cpp +++ b/samples/cpp/squares.cpp @@ -2,10 +2,10 @@ // It loads several images sequentially and tries to find squares in // each image -#include "opencv2/core/core.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include #include @@ -23,8 +23,8 @@ static void help() "Returns sequence of squares detected on the image.\n" "the sequence is stored in the specified memory storage\n" "Call:\n" - "./squares\n" - "Using OpenCV version %s\n" << CV_VERSION << "\n" << endl; + "./squares [file_name (optional)]\n" + "Using OpenCV version " << CV_VERSION << "\n" << endl; } @@ -140,11 +140,18 @@ static void drawSquares( Mat& image, const vector >& squares ) } -int main(int /*argc*/, char** /*argv*/) +int main(int argc, char** argv) { static const char* names[] = { "../data/pic1.png", "../data/pic2.png", "../data/pic3.png", "../data/pic4.png", "../data/pic5.png", "../data/pic6.png", 0 }; help(); + + if( argc > 1) + { + names[0] = argv[1]; + names[1] = "0"; + } + namedWindow( wndname, 1 ); vector > squares; diff --git a/samples/cpp/starter_imagelist.cpp b/samples/cpp/starter_imagelist.cpp index 89df0cc1b5..6f4f71466c 100644 --- a/samples/cpp/starter_imagelist.cpp +++ b/samples/cpp/starter_imagelist.cpp @@ -9,7 +9,7 @@ * easy as CV_PI right? */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include #include diff --git a/samples/cpp/starter_video.cpp b/samples/cpp/starter_video.cpp index d6bf1b7664..2839b03d7e 100644 --- a/samples/cpp/starter_video.cpp +++ b/samples/cpp/starter_video.cpp @@ -12,8 +12,8 @@ */ #include -#include -#include +#include +#include #include #include diff --git a/samples/cpp/stereo_calib.cpp b/samples/cpp/stereo_calib.cpp index 117c9bac5d..842a6492bd 100644 --- a/samples/cpp/stereo_calib.cpp +++ b/samples/cpp/stereo_calib.cpp @@ -22,10 +22,10 @@ GitHub: https://github.com/Itseez/opencv/ ************************************************** */ -#include "opencv2/calib3d/calib3d.hpp" +#include "opencv2/calib3d.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include #include diff --git a/samples/cpp/stereo_match.cpp b/samples/cpp/stereo_match.cpp index e88b139a16..4868a63950 100644 --- a/samples/cpp/stereo_match.cpp +++ b/samples/cpp/stereo_match.cpp @@ -8,9 +8,9 @@ */ #include "opencv2/calib3d/calib3d.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include "opencv2/core/utility.hpp" #include diff --git a/samples/cpp/tree_engine.cpp b/samples/cpp/tree_engine.cpp index 4412588753..96b2adf837 100644 --- a/samples/cpp/tree_engine.cpp +++ b/samples/cpp/tree_engine.cpp @@ -1,5 +1,5 @@ -#include "opencv2/ml/ml.hpp" -#include "opencv2/core/core.hpp" +#include "opencv2/ml.hpp" +#include "opencv2/core.hpp" #include "opencv2/core/utility.hpp" #include #include diff --git a/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp b/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp index 9e04dd912e..93a7b48b19 100644 --- a/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp +++ b/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp @@ -5,7 +5,7 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include using namespace cv; diff --git a/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp b/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp index 213850f995..1834e35e22 100644 --- a/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp +++ b/samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp @@ -6,7 +6,7 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" using namespace cv; diff --git a/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp b/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp index 45db5854e5..80d4d4645b 100644 --- a/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp +++ b/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp @@ -5,10 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include using namespace cv; using namespace std; @@ -24,10 +23,10 @@ int main( int, char** argv ) const char* equalized_window = "Equalized Image"; /// Load image - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); if( src.empty() ) - { cout<<"Usage: ./Histogram_Demo "<"< -#include using namespace std; using namespace cv; @@ -27,11 +26,24 @@ void MatchingMethod( int, void* ); /** * @function main */ -int main( int, char** argv ) +int main( int argc, char** argv ) { + if (argc < 3) + { + cout << "Not enough parameters" << endl; + cout << "Usage:\n./MatchTemplate_Demo " << endl; + return -1; + } + /// Load image and template - img = imread( argv[1], 1 ); - templ = imread( argv[2], 1 ); + img = imread( argv[1], IMREAD_COLOR ); + templ = imread( argv[2], IMREAD_COLOR ); + + if(img.empty() || templ.empty()) + { + cout << "Can't read one of the images" << endl; + return -1; + } /// Create windows namedWindow( image_window, WINDOW_AUTOSIZE ); diff --git a/samples/cpp/tutorial_code/Histograms_Matching/calcBackProject_Demo1.cpp b/samples/cpp/tutorial_code/Histograms_Matching/calcBackProject_Demo1.cpp index ce0e911237..1e2fe928f7 100644 --- a/samples/cpp/tutorial_code/Histograms_Matching/calcBackProject_Demo1.cpp +++ b/samples/cpp/tutorial_code/Histograms_Matching/calcBackProject_Demo1.cpp @@ -4,9 +4,9 @@ * @author OpenCV team */ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include @@ -27,7 +27,13 @@ void Hist_and_Backproj(int, void* ); int main( int, char** argv ) { /// Read the image - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); + + if( src.empty() ) + { cout<<"Usage: ./calcBackProject_Demo1 "< @@ -30,7 +30,7 @@ void pickPoint (int event, int x, int y, int, void* ); int main( int, char** argv ) { /// Read the image - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); /// Transform it to HSV cvtColor( src, hsv, COLOR_BGR2HSV ); diff --git a/samples/cpp/tutorial_code/Histograms_Matching/calcHist_Demo.cpp b/samples/cpp/tutorial_code/Histograms_Matching/calcHist_Demo.cpp index 1540cd85da..27e21e76b2 100644 --- a/samples/cpp/tutorial_code/Histograms_Matching/calcHist_Demo.cpp +++ b/samples/cpp/tutorial_code/Histograms_Matching/calcHist_Demo.cpp @@ -4,11 +4,10 @@ * @author */ -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include -#include using namespace std; using namespace cv; @@ -16,12 +15,19 @@ using namespace cv; /** * @function main */ -int main( int, char** argv ) +int main(int argc, char** argv) { Mat src, dst; /// Load image - src = imread( argv[1], 1 ); + String imageName( "../data/lena.jpg" ); // by default + + if (argc > 1) + { + imageName = argv[1]; + } + + src = imread( imageName, IMREAD_COLOR ); if( src.empty() ) { return -1; } diff --git a/samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp b/samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp index 122e19bebc..4d0123b247 100644 --- a/samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp +++ b/samples/cpp/tutorial_code/Histograms_Matching/compareHist_Demo.cpp @@ -5,10 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include using namespace std; using namespace cv; @@ -26,13 +25,19 @@ int main( int argc, char** argv ) /// Load three images with different environment settings if( argc < 4 ) { - printf("** Error. Usage: ./compareHist_Demo \n"); + printf("** Error. Usage: ./compareHist_Demo \n"); return -1; } - src_base = imread( argv[1], 1 ); - src_test1 = imread( argv[2], 1 ); - src_test2 = imread( argv[3], 1 ); + src_base = imread( argv[1], IMREAD_COLOR ); + src_test1 = imread( argv[2], IMREAD_COLOR ); + src_test2 = imread( argv[3], IMREAD_COLOR ); + + if(src_base.empty() || src_test1.empty() || src_test2.empty()) + { + cout << "Can't read one of the images" << endl; + return -1; + } /// Convert to HSV cvtColor( src_base, hsv_base, COLOR_BGR2HSV ); diff --git a/samples/cpp/tutorial_code/ImgProc/AddingImages.cpp b/samples/cpp/tutorial_code/ImgProc/AddingImages.cpp index 32ce10f4b2..20b09ec32b 100644 --- a/samples/cpp/tutorial_code/ImgProc/AddingImages.cpp +++ b/samples/cpp/tutorial_code/ImgProc/AddingImages.cpp @@ -5,7 +5,7 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include using namespace cv; diff --git a/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp b/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp index 9ffe1563de..b24451de35 100644 --- a/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp +++ b/samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp @@ -5,7 +5,7 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include using namespace cv; diff --git a/samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp b/samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp index e8fac91300..626bd8b960 100644 --- a/samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp @@ -4,11 +4,9 @@ * @author OpenCV team */ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include -#include +#include "opencv2/highgui.hpp" using namespace cv; @@ -32,7 +30,7 @@ void Dilation( int, void* ); int main( int, char** argv ) { /// Load an image - src = imread( argv[1] ); + src = imread( argv[1], IMREAD_COLOR ); if( src.empty() ) { return -1; } diff --git a/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp b/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp index 3f43eeeedb..97304a4612 100644 --- a/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp @@ -4,11 +4,9 @@ * @author OpenCV team */ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include -#include +#include "opencv2/highgui.hpp" using namespace cv; @@ -34,7 +32,7 @@ void Morphology_Operations( int, void* ); int main( int, char** argv ) { /// Load an image - src = imread( argv[1] ); + src = imread( argv[1], IMREAD_COLOR ); if( src.empty() ) { return -1; } @@ -67,7 +65,6 @@ int main( int, char** argv ) */ void Morphology_Operations( int, void* ) { - // Since MORPH_X : 2,3,4,5 and 6 int operation = morph_operator + 2; diff --git a/samples/cpp/tutorial_code/ImgProc/Pyramids.cpp b/samples/cpp/tutorial_code/ImgProc/Pyramids.cpp index c52c0e04f4..e4b7096e6d 100644 --- a/samples/cpp/tutorial_code/ImgProc/Pyramids.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Pyramids.cpp @@ -4,12 +4,9 @@ * @author OpenCV team */ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include -#include -#include +#include "opencv2/highgui.hpp" using namespace cv; diff --git a/samples/cpp/tutorial_code/ImgProc/Smoothing.cpp b/samples/cpp/tutorial_code/ImgProc/Smoothing.cpp index e7ac4d40f5..6a84da073b 100644 --- a/samples/cpp/tutorial_code/ImgProc/Smoothing.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Smoothing.cpp @@ -3,13 +3,10 @@ * brief Sample code for simple filters * author OpenCV team */ -#include -#include -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/features2d/features2d.hpp" +#include "opencv2/highgui.hpp" using namespace std; using namespace cv; @@ -35,7 +32,7 @@ int main( void ) namedWindow( window_name, WINDOW_AUTOSIZE ); /// Load the source image - src = imread( "../data/lena.jpg", 1 ); + src = imread( "../data/lena.jpg", IMREAD_COLOR ); if( display_caption( "Original Image" ) != 0 ) { return 0; } diff --git a/samples/cpp/tutorial_code/ImgProc/Threshold.cpp b/samples/cpp/tutorial_code/ImgProc/Threshold.cpp index 0944f6cd3b..36943028d9 100644 --- a/samples/cpp/tutorial_code/ImgProc/Threshold.cpp +++ b/samples/cpp/tutorial_code/ImgProc/Threshold.cpp @@ -4,11 +4,9 @@ * @author OpenCV team */ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include -#include +#include "opencv2/highgui.hpp" using namespace cv; @@ -35,10 +33,13 @@ void Threshold_Demo( int, void* ); int main( int, char** argv ) { /// Load an image - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); + + if( src.empty() ) + { return -1; } /// Convert the image to Gray - cvtColor( src, src_gray, COLOR_RGB2GRAY ); + cvtColor( src, src_gray, COLOR_BGR2GRAY ); /// Create a window to display results namedWindow( window_name, WINDOW_AUTOSIZE ); diff --git a/samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp index 92e10e4b0d..8b94bb3207 100644 --- a/samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp @@ -4,11 +4,9 @@ * @author OpenCV team */ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include -#include +#include "opencv2/highgui.hpp" using namespace cv; @@ -50,7 +48,7 @@ static void CannyThreshold(int, void*) int main( int, char** argv ) { /// Load an image - src = imread( argv[1] ); + src = imread( argv[1], IMREAD_COLOR ); if( src.empty() ) { return -1; } diff --git a/samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp index 00184a3f87..edbb1e7387 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp @@ -5,10 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include using namespace cv; using namespace std; @@ -31,7 +30,7 @@ int main( int, char** argv ) Mat src, warp_dst, warp_rotate_dst; /// Load the image - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); /// Set the dst image the same type and size as src warp_dst = Mat::zeros( src.rows, src.cols, src.type() ); diff --git a/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp index 02f03813f2..81bb3f8895 100644 --- a/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp @@ -5,8 +5,8 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include using namespace std; @@ -63,7 +63,7 @@ int main(int argc, char** argv) } // Read the image - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); if( src.empty() ) { diff --git a/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp index 2d9b7b6454..5610cfefe5 100644 --- a/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp @@ -5,10 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include using namespace cv; using namespace std; @@ -39,7 +38,7 @@ void Probabilistic_Hough( int, void* ); int main( int, char** argv ) { /// Read the image - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); if( src.empty() ) { help(); diff --git a/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp index f0d45e715b..386b26da74 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp @@ -4,11 +4,9 @@ * @author OpenCV team */ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include -#include +#include "opencv2/highgui.hpp" using namespace cv; @@ -26,7 +24,7 @@ int main( int, char** argv ) const char* window_name = "Laplace Demo"; /// Load an image - src = imread( argv[1] ); + src = imread( argv[1], IMREAD_COLOR ); if( src.empty() ) { return -1; } diff --git a/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp index 49727e9cf0..b5a76faa47 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp @@ -5,10 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include using namespace cv; @@ -27,7 +26,7 @@ void update_map( void ); int main( int, char** argv ) { /// Load the image - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); /// Create dst, map_x and map_y with the same size as src: dst.create( src.size(), src.type() ); diff --git a/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp b/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp index 7d57e8ec6c..efe4c71691 100644 --- a/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp @@ -4,11 +4,9 @@ * @author OpenCV team */ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include -#include +#include "opencv2/highgui.hpp" using namespace cv; @@ -26,7 +24,7 @@ int main( int, char** argv ) int ddepth = CV_16S; /// Load an image - src = imread( argv[1] ); + src = imread( argv[1], IMREAD_COLOR ); if( src.empty() ) { return -1; } diff --git a/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp b/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp index 5f786d568f..6da2b296b2 100644 --- a/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp @@ -4,11 +4,9 @@ * @author OpenCV team */ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include -#include +#include "opencv2/highgui.hpp" using namespace cv; @@ -28,7 +26,7 @@ int main( int, char** argv ) int c; /// Load an image - src = imread( argv[1] ); + src = imread( argv[1], IMREAD_COLOR ); if( src.empty() ) { diff --git a/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp b/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp index 3c580bb216..6fc04d8f41 100644 --- a/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp +++ b/samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp @@ -4,11 +4,9 @@ * @author OpenCV team */ -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include -#include +#include "opencv2/highgui.hpp" using namespace cv; @@ -30,7 +28,7 @@ int main ( int, char** argv ) int c; /// Load an image - src = imread( argv[1] ); + src = imread( argv[1], IMREAD_COLOR ); if( src.empty() ) { return -1; } diff --git a/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp b/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp index 6a6de95394..b831441b33 100644 --- a/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp +++ b/samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp @@ -5,11 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include -#include using namespace cv; using namespace std; @@ -28,7 +26,7 @@ void thresh_callback(int, void* ); int main( int, char** argv ) { /// Load source image - src = imread(argv[1]); + src = imread(argv[1], IMREAD_COLOR); if (src.empty()) { cerr << "No image supplied ..." << endl; diff --git a/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo1.cpp b/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo1.cpp index a9c22e60fc..29d75515cf 100644 --- a/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo1.cpp +++ b/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo1.cpp @@ -5,11 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include -#include using namespace cv; using namespace std; @@ -28,7 +26,7 @@ void thresh_callback(int, void* ); int main( int, char** argv ) { /// Load source image and convert it to gray - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); /// Convert image to gray and blur it cvtColor( src, src_gray, COLOR_BGR2GRAY ); diff --git a/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo2.cpp b/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo2.cpp index c6fd379328..742c6cf0a9 100644 --- a/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo2.cpp +++ b/samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo2.cpp @@ -5,11 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include -#include using namespace cv; using namespace std; @@ -28,7 +26,7 @@ void thresh_callback(int, void* ); int main( int, char** argv ) { /// Load source image and convert it to gray - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); /// Convert image to gray and blur it cvtColor( src, src_gray, COLOR_BGR2GRAY ); diff --git a/samples/cpp/tutorial_code/ShapeDescriptors/hull_demo.cpp b/samples/cpp/tutorial_code/ShapeDescriptors/hull_demo.cpp index 0b354291a9..7fe5b71f98 100644 --- a/samples/cpp/tutorial_code/ShapeDescriptors/hull_demo.cpp +++ b/samples/cpp/tutorial_code/ShapeDescriptors/hull_demo.cpp @@ -5,11 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include -#include using namespace cv; using namespace std; @@ -28,7 +26,7 @@ void thresh_callback(int, void* ); int main( int, char** argv ) { /// Load source image and convert it to gray - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); /// Convert image to gray and blur it cvtColor( src, src_gray, COLOR_BGR2GRAY ); diff --git a/samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp b/samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp index c3a5cbf60a..4064048df7 100644 --- a/samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp +++ b/samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp @@ -5,11 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include -#include using namespace cv; using namespace std; @@ -28,7 +26,7 @@ void thresh_callback(int, void* ); int main( int, char** argv ) { /// Load source image and convert it to gray - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); /// Convert image to gray and blur it cvtColor( src, src_gray, COLOR_BGR2GRAY ); diff --git a/samples/cpp/tutorial_code/ShapeDescriptors/pointPolygonTest_demo.cpp b/samples/cpp/tutorial_code/ShapeDescriptors/pointPolygonTest_demo.cpp index f55f8f6879..757b8dc0f8 100644 --- a/samples/cpp/tutorial_code/ShapeDescriptors/pointPolygonTest_demo.cpp +++ b/samples/cpp/tutorial_code/ShapeDescriptors/pointPolygonTest_demo.cpp @@ -4,11 +4,9 @@ * @author OpenCV team */ -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include -#include using namespace cv; using namespace std; diff --git a/samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp b/samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp index c5dceab48b..52d7561522 100644 --- a/samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp +++ b/samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp @@ -3,12 +3,11 @@ * @brief Demo code for detecting corners using OpenCV built-in functions * @author OpenCV team */ + #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include -#include using namespace cv; using namespace std; @@ -40,7 +39,7 @@ void myHarris_function( int, void* ); int main( int, char** argv ) { /// Load source image and convert it to gray - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); cvtColor( src, src_gray, COLOR_BGR2GRAY ); /// Set some parameters diff --git a/samples/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp b/samples/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp index 4314a97e26..4f1df4b844 100644 --- a/samples/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp +++ b/samples/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp @@ -5,11 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include -#include using namespace cv; using namespace std; @@ -31,7 +29,7 @@ void cornerHarris_demo( int, void* ); int main( int, char** argv ) { /// Load source image and convert it to gray - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); cvtColor( src, src_gray, COLOR_BGR2GRAY ); /// Create a window and a trackbar diff --git a/samples/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp b/samples/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp index 775e566ce7..8e4876bcee 100644 --- a/samples/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp +++ b/samples/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp @@ -5,11 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include -#include using namespace cv; using namespace std; @@ -32,7 +30,7 @@ void goodFeaturesToTrack_Demo( int, void* ); int main( int, char** argv ) { /// Load source image and convert it to gray - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); cvtColor( src, src_gray, COLOR_BGR2GRAY ); /// Create Window diff --git a/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp b/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp index cff59f5390..da357e7407 100644 --- a/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp +++ b/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp @@ -5,11 +5,9 @@ */ #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/highgui.hpp" +#include "opencv2/imgproc.hpp" #include -#include -#include using namespace cv; using namespace std; @@ -32,7 +30,7 @@ void goodFeaturesToTrack_Demo( int, void* ); int main( int, char** argv ) { /// Load source image and convert it to gray - src = imread( argv[1], 1 ); + src = imread( argv[1], IMREAD_COLOR ); cvtColor( src, src_gray, COLOR_BGR2GRAY ); /// Create Window diff --git a/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp b/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp index 0322519839..580fe73792 100644 --- a/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp +++ b/samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp @@ -21,7 +21,7 @@ using namespace std; static void help() { cout << "This is a camera calibration sample." << endl - << "Usage: calibration configurationFile" << endl + << "Usage: camera_calibration [configuration_file -- default ./default.xml]" << endl << "Near the sample file you'll find the configuration file, which has detailed help of " "how to edit it. It may be any OpenCV supported file format XML/YAML." << endl; } @@ -415,7 +415,7 @@ int main(int argc, char* argv[]) for(size_t i = 0; i < s.imageList.size(); i++ ) { - view = imread(s.imageList[i], 1); + view = imread(s.imageList[i], IMREAD_COLOR); if(view.empty()) continue; remap(view, rview, map1, map2, INTER_LINEAR); diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp index fa2bad442e..b548bed463 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp @@ -11,8 +11,8 @@ #include "ModelRegistration.h" #include "Utils.h" -#include -#include +#include +#include // For text int fontFace = cv::FONT_ITALIC; diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp index 6de590e684..4808e64135 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_detection.cpp @@ -2,11 +2,11 @@ #include #include // OpenCV -#include +#include #include -#include -#include -#include +#include +#include +#include #include // PnP Tutorial #include "Mesh.h" diff --git a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp index da775a063e..5ddb83f0da 100644 --- a/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp +++ b/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/main_registration.cpp @@ -1,10 +1,10 @@ // C++ #include // OpenCV -#include -#include -#include -#include +#include +#include +#include +#include // PnP Tutorial #include "Mesh.h" #include "Model.h" diff --git a/samples/cpp/tutorial_code/calib3d/stereoBM/SBM_Sample.cpp b/samples/cpp/tutorial_code/calib3d/stereoBM/SBM_Sample.cpp index 90fa2801be..d114a9582f 100644 --- a/samples/cpp/tutorial_code/calib3d/stereoBM/SBM_Sample.cpp +++ b/samples/cpp/tutorial_code/calib3d/stereoBM/SBM_Sample.cpp @@ -4,12 +4,10 @@ * @author A. Huaman */ -#include #include -#include "opencv2/calib3d/calib3d.hpp" -#include "opencv2/core/core.hpp" +#include "opencv2/calib3d.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" using namespace cv; diff --git a/samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp b/samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp index dbebeea923..e23ab1c326 100644 --- a/samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp +++ b/samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp @@ -1,7 +1,7 @@ -#include "opencv2/core/core.hpp" -#include "opencv2/imgproc/imgproc.hpp" +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" #include "opencv2/imgcodecs.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/highgui.hpp" #include diff --git a/samples/cpp/tutorial_code/core/file_input_output/file_input_output.cpp b/samples/cpp/tutorial_code/core/file_input_output/file_input_output.cpp index 8fc722df78..faeacfb967 100644 --- a/samples/cpp/tutorial_code/core/file_input_output/file_input_output.cpp +++ b/samples/cpp/tutorial_code/core/file_input_output/file_input_output.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp b/samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp index c673c66592..47a5547837 100644 --- a/samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp +++ b/samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp @@ -16,7 +16,7 @@ static void help() << " we take an input image and divide the native color palette (255) with the " << endl << "input. Shows C operator[] method, iterators and at function for on-the-fly item address calculation."<< endl << "Usage:" << endl - << "./howToScanImages imageNameToUse divideWith [G]" << endl + << "./how_to_scan_images [G]" << endl << "if you add a G parameter the image is processed in gray scale" << endl << "--------------------------------------------------------------------------" << endl << endl; diff --git a/samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp b/samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp index b6aa6131de..79e7c99d85 100644 --- a/samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp +++ b/samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp @@ -1,12 +1,9 @@ //! [head] -#include #include -#include -#include +#include #include "opencv2/imgcodecs.hpp" -#include -#include +#include using namespace cv; // The new C++ interface API is inside this namespace. Import it. using namespace std; diff --git a/samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp b/samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp index f0cbca1695..8eb9ca7efd 100644 --- a/samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp +++ b/samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp @@ -1,5 +1,3 @@ -#include -#include #include #include #include @@ -25,38 +23,44 @@ int main( int argc, char* argv[]) help(argv[0]); const char* filename = argc >=2 ? argv[1] : "../data/lena.jpg"; - Mat I, J, K; + Mat src, dst0, dst1; if (argc >= 3 && !strcmp("G", argv[2])) - I = imread( filename, IMREAD_GRAYSCALE); + src = imread( filename, IMREAD_GRAYSCALE); else - I = imread( filename, IMREAD_COLOR); + src = imread( filename, IMREAD_COLOR); + + if (src.empty()) + { + cerr << "Can't open image [" << filename << "]" << endl; + return -1; + } namedWindow("Input", WINDOW_AUTOSIZE); namedWindow("Output", WINDOW_AUTOSIZE); - imshow("Input", I); + imshow( "Input", src ); double t = (double)getTickCount(); - Sharpen(I, J); + Sharpen( src, dst0 ); t = ((double)getTickCount() - t)/getTickFrequency(); cout << "Hand written function times passed in seconds: " << t << endl; - imshow("Output", J); - waitKey(0); + imshow( "Output", dst0 ); + waitKey(); - Mat kern = (Mat_(3,3) << 0, -1, 0, + Mat kernel = (Mat_(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0); t = (double)getTickCount(); - filter2D(I, K, I.depth(), kern ); + filter2D( src, dst1, src.depth(), kernel ); t = ((double)getTickCount() - t)/getTickFrequency(); cout << "Built-in filter2D time passed in seconds: " << t << endl; - imshow("Output", K); + imshow( "Output", dst1 ); - waitKey(0); + waitKey(); return 0; } void Sharpen(const Mat& myImage,Mat& Result) diff --git a/samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp b/samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp index 7fb060bddd..77ea93827f 100644 --- a/samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp +++ b/samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp @@ -1,6 +1,6 @@ /* For description look into the help() function. */ -#include "opencv2/core/core.hpp" +#include "opencv2/core.hpp" #include using namespace std; @@ -15,7 +15,7 @@ static void help() << "That is, cv::Mat M(...); M.create and cout << M. " << endl << "Shows how output can be formated to OpenCV, python, numpy, csv and C styles." << endl << "Usage:" << endl - << "./cvout_sample" << endl + << "./mat_the_basic_image_container" << endl << "--------------------------------------------------------------------------" << endl << endl; } diff --git a/samples/cpp/tutorial_code/imgcodecs/GDAL_IO/gdal-image.cpp b/samples/cpp/tutorial_code/imgcodecs/GDAL_IO/gdal-image.cpp index 6e7c950a26..66084df78a 100644 --- a/samples/cpp/tutorial_code/imgcodecs/GDAL_IO/gdal-image.cpp +++ b/samples/cpp/tutorial_code/imgcodecs/GDAL_IO/gdal-image.cpp @@ -3,9 +3,9 @@ */ // OpenCV Headers -#include "opencv2/core/core.hpp" -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/highgui/highgui.hpp" +#include "opencv2/core.hpp" +#include "opencv2/imgproc.hpp" +#include "opencv2/highgui.hpp" // C++ Standard Libraries #include @@ -159,8 +159,8 @@ int main( int argc, char* argv[] ){ * Check input arguments */ if( argc < 3 ){ - cout << "usage: " << argv[0] << " " << endl; - return 1; + cout << "usage: " << argv[0] << " " << endl; + return -1; } // load the image (note that we don't have the projection information. You will diff --git a/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp b/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp index 558cb66d55..456286741e 100644 --- a/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp +++ b/samples/cpp/tutorial_code/introduction/display_image/display_image.cpp @@ -1,7 +1,7 @@ //! [includes] -#include +#include #include -#include +#include #include #include @@ -16,7 +16,7 @@ using namespace std; int main( int argc, char** argv ) { //! [load] - string imageName("../data/HappyFish.jpg"); // by default + String imageName( "../data/HappyFish.jpg" ); // by default if( argc > 1) { imageName = argv[1]; @@ -28,7 +28,7 @@ int main( int argc, char** argv ) //! [mat] //! [imread] - image = imread(imageName.c_str(), IMREAD_COLOR); // Read the file + image = imread( imageName, IMREAD_COLOR ); // Read the file //! [imread] if( image.empty() ) // Check for invalid input diff --git a/samples/cpp/tutorial_code/photo/decolorization/decolor.cpp b/samples/cpp/tutorial_code/photo/decolorization/decolor.cpp index 067bad1178..13c1b0c5f7 100644 --- a/samples/cpp/tutorial_code/photo/decolorization/decolor.cpp +++ b/samples/cpp/tutorial_code/photo/decolorization/decolor.cpp @@ -27,13 +27,13 @@ using namespace cv; int main(int argc, char *argv[]) { CV_Assert(argc == 2); - Mat I; - I = imread(argv[1]); + Mat src; + src = imread(argv[1], IMREAD_COLOR); - Mat gray = Mat(I.size(),CV_8UC1); - Mat color_boost = Mat(I.size(),CV_8UC3); + Mat gray = Mat(src.size(),CV_8UC1); + Mat color_boost = Mat(src.size(),CV_8UC3); - decolor(I,gray,color_boost); + decolor(src,gray,color_boost); imshow("grayscale",gray); imshow("color_boost",color_boost); waitKey(0); diff --git a/samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp b/samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp index f81204c88b..8a24ddb7e6 100644 --- a/samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp +++ b/samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp @@ -35,9 +35,9 @@ int main(int argc, char* argv[]) int num,type; - Mat I = imread(argv[1]); + Mat src = imread(argv[1], IMREAD_COLOR); - if(I.empty()) + if(src.empty()) { cout << "Image not found" << endl; exit(0); @@ -71,25 +71,25 @@ int main(int argc, char* argv[]) cin >> type; - edgePreservingFilter(I,img,type); + edgePreservingFilter(src,img,type); imshow("Edge Preserve Smoothing",img); } else if(num == 2) { - detailEnhance(I,img); + detailEnhance(src,img); imshow("Detail Enhanced",img); } else if(num == 3) { Mat img1; - pencilSketch(I,img1, img, 10 , 0.1f, 0.03f); + pencilSketch(src,img1, img, 10 , 0.1f, 0.03f); imshow("Pencil Sketch",img1); imshow("Color Pencil Sketch",img); } else if(num == 4) { - stylization(I,img); + stylization(src,img); imshow("Stylization",img); } waitKey(0); diff --git a/samples/cpp/tutorial_code/video/bg_sub.cpp b/samples/cpp/tutorial_code/video/bg_sub.cpp index d37c7bd0f9..94799f388b 100644 --- a/samples/cpp/tutorial_code/video/bg_sub.cpp +++ b/samples/cpp/tutorial_code/video/bg_sub.cpp @@ -38,9 +38,9 @@ void help() << " OpenCV. You can process both videos (-vid) and images (-img)." << endl << endl << "Usage:" << endl - << "./bs {-vid