From b7fa9697f6b9d18495959f89cc3b3425709bbcdd Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Tue, 4 Jul 2017 12:31:02 +0300 Subject: [PATCH 1/2] text: remove duplicated create method in OCRHMMDecoder class --- modules/text/include/opencv2/text/ocr.hpp | 8 -------- modules/text/src/ocr_hmm_decoder.cpp | 10 ---------- 2 files changed, 18 deletions(-) diff --git a/modules/text/include/opencv2/text/ocr.hpp b/modules/text/include/opencv2/text/ocr.hpp index b70b30af7f7..f8a8e8cc2fa 100644 --- a/modules/text/include/opencv2/text/ocr.hpp +++ b/modules/text/include/opencv2/text/ocr.hpp @@ -290,14 +290,6 @@ class CV_EXPORTS_W OCRHMMDecoder : public BaseOCR @param mode HMM Decoding algorithm. Only OCR_DECODER_VITERBI is available for the moment (). */ - static Ptr create(const Ptr classifier,// The character classifier with built in feature extractor - const std::string& vocabulary, // The language vocabulary (chars when ASCII English text) - // size() must be equal to the number of classes - InputArray transition_probabilities_table, // Table with transition probabilities between character pairs - // cols == rows == vocabulary.size() - InputArray emission_probabilities_table, // Table with observation emission probabilities - // cols == rows == vocabulary.size() - decoder_mode mode = OCR_DECODER_VITERBI); // HMM Decoding algorithm (only Viterbi for the moment) CV_WRAP static Ptr create(const Ptr classifier,// The character classifier with built in feature extractor const String& vocabulary, // The language vocabulary (chars when ASCII English text) diff --git a/modules/text/src/ocr_hmm_decoder.cpp b/modules/text/src/ocr_hmm_decoder.cpp index 598aeb31c40..6d61578bdac 100644 --- a/modules/text/src/ocr_hmm_decoder.cpp +++ b/modules/text/src/ocr_hmm_decoder.cpp @@ -665,16 +665,6 @@ class OCRHMMDecoderImpl : public OCRHMMDecoder } }; -Ptr OCRHMMDecoder::create( Ptr _classifier, - const string& _vocabulary, - InputArray transition_p, - InputArray emission_p, - decoder_mode _mode) -{ - return makePtr(_classifier, _vocabulary, transition_p, emission_p, _mode); -} - - Ptr OCRHMMDecoder::create( Ptr _classifier, const String& _vocabulary, InputArray transition_p, From 2b4c35766a4b182ac37f594e1cc9b16a62614e16 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 27 Aug 2018 19:35:54 +0000 Subject: [PATCH 2/2] hdf5: fix atread(string) no need to append null-terminated symbol --- modules/hdf/src/hdf5.cpp | 7 +++++-- modules/hdf/test/test_hdf5.cpp | 24 +++++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/modules/hdf/src/hdf5.cpp b/modules/hdf/src/hdf5.cpp index a24092a4e6a..2769bdf77b2 100644 --- a/modules/hdf/src/hdf5.cpp +++ b/modules/hdf/src/hdf5.cpp @@ -441,10 +441,13 @@ void HDF5Impl::atread(String* value, const String& atlabel) CV_Error_(Error::StsInternal, ("Attribute '%s' is not of string type!", atlabel.c_str())); } size_t size = H5Tget_size(atype); - *value = String(size, 0); // allocate space + AutoBuffer buf(size); hid_t atype_mem = H5Tget_native_type(atype, H5T_DIR_ASCEND); - H5Aread(attr, atype_mem, const_cast(value->c_str())); + H5Aread(attr, atype_mem, buf.data()); + if (size > 0 && buf[size - 1] == '\0') + size--; + value->assign(buf.data(), size); H5Tclose(atype_mem); H5Tclose(atype); diff --git a/modules/hdf/test/test_hdf5.cpp b/modules/hdf/test/test_hdf5.cpp index a7610f72cee..52348c0f247 100644 --- a/modules/hdf/test/test_hdf5.cpp +++ b/modules/hdf/test/test_hdf5.cpp @@ -284,9 +284,27 @@ TEST_F(HDF5_Test, test_attribute_String) m_hdf_io->atwrite(attr_value, attr_name); - String expected_attr_value; - m_hdf_io->atread(&expected_attr_value, attr_name); - EXPECT_EQ(attr_value.compare(expected_attr_value), 0); + String got_attr_value; + m_hdf_io->atread(&got_attr_value, attr_name); + EXPECT_EQ(attr_value, got_attr_value); + + m_hdf_io->close(); +} + +TEST_F(HDF5_Test, test_attribute_String_empty) +{ + reset(); + + String attr_name = "test-empty-string"; + String attr_value; + + m_hdf_io = hdf::open(m_filename); + + m_hdf_io->atwrite(attr_value, attr_name); + + String got_attr_value; + m_hdf_io->atread(&got_attr_value, attr_name); + EXPECT_EQ(attr_value, got_attr_value); m_hdf_io->close(); }