mirror of
https://github.com/opencv/opencv.git
synced 2024-11-27 12:40:05 +08:00
Merge pull request #26446 from dkurt:file_storage_empty_and_1d_mat
* Change style of empty and 1d Mat in FileStorage * Remove misleading 1d Mat test
This commit is contained in:
parent
37c2af63f0
commit
c230841105
@ -12,7 +12,7 @@ void write( FileStorage& fs, const String& name, const Mat& m )
|
||||
{
|
||||
char dt[22];
|
||||
|
||||
if( m.dims <= 2 )
|
||||
if( m.dims == 2 || m.empty() )
|
||||
{
|
||||
fs.startWriteStruct(name, FileNode::MAP, String("opencv-matrix"));
|
||||
fs << "rows" << m.rows;
|
||||
@ -151,6 +151,11 @@ void read(const FileNode& node, Mat& m, const Mat& default_mat)
|
||||
CV_Assert(!data_node.empty());
|
||||
|
||||
size_t nelems = data_node.size();
|
||||
if (nelems == 0)
|
||||
{
|
||||
m = Mat();
|
||||
return;
|
||||
}
|
||||
CV_Assert(nelems == m.total()*m.channels());
|
||||
|
||||
data_node.readRaw(dt, (uchar*)m.ptr(), m.total()*m.elemSize());
|
||||
|
@ -2018,7 +2018,25 @@ T fsWriteRead(const T& expectedValue, const char* ext)
|
||||
return value;
|
||||
}
|
||||
|
||||
void testExactMat(const Mat& src, const char* ext)
|
||||
{
|
||||
bool srcIsEmpty = src.empty();
|
||||
Mat dst = fsWriteRead(src, ext);
|
||||
EXPECT_EQ(dst.empty(), srcIsEmpty);
|
||||
EXPECT_EQ(src.dims, dst.dims);
|
||||
EXPECT_EQ(src.size, dst.size);
|
||||
if (!srcIsEmpty)
|
||||
{
|
||||
EXPECT_EQ(0.0, cv::norm(src, dst, NORM_INF));
|
||||
}
|
||||
}
|
||||
|
||||
typedef testing::TestWithParam<const char*> FileStorage_exact_type;
|
||||
TEST_P(FileStorage_exact_type, empty_mat)
|
||||
{
|
||||
testExactMat(Mat(), GetParam());
|
||||
}
|
||||
|
||||
TEST_P(FileStorage_exact_type, long_int)
|
||||
{
|
||||
for (const int64_t expected : std::vector<int64_t>{INT64_MAX, INT64_MIN, -1, 1, 0})
|
||||
|
Loading…
Reference in New Issue
Block a user