Skip to content

Commit c9c5a75

Browse files
committed
enable unicode characters in filenames
1 parent f5936ef commit c9c5a75

File tree

6 files changed

+215
-2
lines changed

6 files changed

+215
-2
lines changed

src/ioutils/DICe_ImageIO.cpp

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,26 @@ void read_image_dimensions(const char * file_name,
204204
else{
205205
DEBUG_MSG("read_image_dimensions(): (opencv) file name: " << file_name);
206206
cv::Mat image = cv::imread(file_name, cv::ImreadModes::IMREAD_GRAYSCALE);
207+
if (image.empty()) {
208+
DEBUG_MSG("utils::read_image(): image is empty, it could have unicode characters in the name so trying to read with a buffer instead");
209+
std::ifstream f(file_name,std::iostream::binary);
210+
if(!f.good()){
211+
std::cout << "utils::read_image_dimensions(): image read failed." << std::endl;
212+
height = 0;
213+
width = 0;
214+
return;
215+
}
216+
std::filebuf* pbuf = f.rdbuf();
217+
size_t size = pbuf->pubseekoff(0, f.end, f.in);
218+
pbuf->pubseekpos(0, f.in);
219+
std::vector<uchar> buffer(size);
220+
pbuf->sgetn((char*)buffer.data(), size);
221+
image = cv::imdecode(buffer, cv::IMREAD_GRAYSCALE);
222+
if (image.empty()) {
223+
std::cout << "utils::read_image_dimensions(): image read failed." << std::endl;
224+
TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,"");
225+
}
226+
}
207227
height = image.rows;
208228
width = image.cols;
209229
}
@@ -387,6 +407,25 @@ void read_image(const char * file_name,
387407
// read the image using opencv:
388408
cv::Mat image;
389409
image = cv::imread(file_name, cv::ImreadModes::IMREAD_GRAYSCALE);
410+
// make sure the filename didn't have any unicode characters causing problems
411+
if (image.empty()) {
412+
DEBUG_MSG("utils::read_image(): image is empty, it could have unicode characters in the name so trying to read with a buffer instead");
413+
std::ifstream f(file_name,std::iostream::binary);
414+
if(!f.good()){
415+
std::cout << "utils::read_image(): image read failed." << std::endl;
416+
}else{
417+
std::filebuf* pbuf = f.rdbuf();
418+
size_t size = pbuf->pubseekoff(0, f.end, f.in);
419+
pbuf->pubseekpos(0, f.in);
420+
std::vector<uchar> buffer(size);
421+
pbuf->sgetn((char*)buffer.data(), size);
422+
image = cv::imdecode(buffer, cv::IMREAD_GRAYSCALE);
423+
if (image.empty()) {
424+
std::cout << "utils::read_image(): image read failed." << std::endl;
425+
TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,"");
426+
}
427+
}
428+
}
390429
width = sub_w==0?image.cols:sub_w;
391430
height = sub_h==0?image.rows:sub_h;
392431
assert(width+sub_offset_x <= image.cols);
@@ -630,8 +669,28 @@ cv::Mat read_image(const char * file_name){
630669
}
631670
}
632671
return img;
633-
}else
634-
return cv::imread(file_name,cv::IMREAD_GRAYSCALE);
672+
}else{
673+
cv::Mat image = cv::imread(file_name,cv::IMREAD_GRAYSCALE);
674+
if (image.empty()) {
675+
DEBUG_MSG("utils::read_image(): image is empty, it could have unicode characters in the name so trying to read with a buffer instead");
676+
std::ifstream f(file_name,std::iostream::binary);
677+
if(!f.good()){
678+
std::cout << "utils::read_image(): image read failed." << std::endl;
679+
}else{
680+
std::filebuf* pbuf = f.rdbuf();
681+
size_t size = pbuf->pubseekoff(0, f.end, f.in);
682+
pbuf->pubseekpos(0, f.in);
683+
std::vector<uchar> buffer(size);
684+
pbuf->sgetn((char*)buffer.data(), size);
685+
image = cv::imdecode(buffer, cv::IMREAD_GRAYSCALE);
686+
if (image.empty()) {
687+
std::cout << "utils::read_image(): image read failed." << std::endl;
688+
TEUCHOS_TEST_FOR_EXCEPTION(true,std::runtime_error,"");
689+
}
690+
}
691+
}
692+
return image;
693+
}
635694
}
636695

637696
template <typename S>
516 KB
Binary file not shown.

tests/regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
SET(REGRESSION_TESTS
1010
single_speckled_shift
1111
incremental
12+
unicode_filename
1213
conformal_subset_def
1314
dic_challenge_12
1415
dic_challenge_12_sorted
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
***
2+
*** Digital Image Correlation Engine (DICe), (git sha1: v3.0-beta.3-10-gd40d9e-dirty) Copyright 2021 National Technology & Engineering Solutions of Sandia, LLC (NTESS)
3+
***
4+
*** Reference image: ../../component/images/æbärnɃ0.tif
5+
*** Deformed image: ../../component/images/æbärnɃ0.tif
6+
*** DIC method : local
7+
*** Correlation method: ZNSSD
8+
*** Interpolation method: KEYS_FOURTH
9+
*** Image gradient method: FINITE_DIFFERENCE
10+
*** Optimization method: GRADIENT_BASED
11+
*** Projection method: DISPLACEMENT_BASED
12+
*** Guess initialization method: USE_FIELD_VALUES
13+
*** Seed location: N/A
14+
*** Shape functions: Translation (u,v) Rotation (theta) Normal Strain (ex,ey) Shear Strain (gamma_xy)
15+
*** Incremental correlation: false
16+
*** Subset size: 15
17+
*** Step size: x 50 y 50 (-1 implies not regular grid)
18+
*** Strain window: N/A
19+
*** Coordinates given with (0,0) as upper left corner of image, x positive right, y positive down
20+
***
21+
COORDINATE_X,COORDINATE_Y,DISPLACEMENT_X,DISPLACEMENT_Y
22+
1.4000E+01,1.4000E+01,4.4044E-14,2.4566E-14
23+
1.4000E+01,6.4000E+01,-9.1844E-15,-1.1572E-15
24+
1.4000E+01,1.1400E+02,1.5927E-14,5.5322E-15
25+
1.4000E+01,1.6400E+02,-1.1662E-15,1.5099E-14
26+
1.4000E+01,2.1400E+02,1.5579E-14,2.3189E-14
27+
1.4000E+01,2.6400E+02,3.0933E-14,-1.5367E-14
28+
1.4000E+01,3.1400E+02,1.9098E-14,-1.8475E-14
29+
1.4000E+01,3.6400E+02,5.9706E-14,-7.3713E-16
30+
1.4000E+01,4.1400E+02,-7.1643E-15,-3.5990E-14
31+
1.4000E+01,4.6400E+02,1.5983E-14,-5.8014E-14
32+
6.4000E+01,4.6400E+02,3.2603E-14,-9.8172E-15
33+
6.4000E+01,4.1400E+02,-1.7824E-14,-3.4804E-15
34+
6.4000E+01,3.6400E+02,-3.0916E-14,1.7249E-14
35+
6.4000E+01,3.1400E+02,1.0252E-15,1.4212E-14
36+
6.4000E+01,2.6400E+02,2.1704E-14,-2.0368E-14
37+
6.4000E+01,2.1400E+02,2.6899E-14,1.8397E-14
38+
6.4000E+01,1.6400E+02,4.2431E-14,-9.6168E-16
39+
6.4000E+01,1.1400E+02,-3.9176E-15,7.0447E-15
40+
6.4000E+01,6.4000E+01,-3.7059E-14,-1.0107E-15
41+
6.4000E+01,1.4000E+01,-2.5382E-15,8.0775E-15
42+
1.1400E+02,1.4000E+01,8.1800E-14,-1.6392E-14
43+
1.1400E+02,6.4000E+01,9.6078E-15,-1.6542E-14
44+
1.1400E+02,1.1400E+02,2.3031E-14,6.8982E-14
45+
1.1400E+02,1.6400E+02,3.5483E-14,-2.7076E-14
46+
1.1400E+02,2.1400E+02,-1.3265E-15,-4.1625E-14
47+
1.1400E+02,2.6400E+02,-1.0075E-14,2.0385E-14
48+
1.1400E+02,3.1400E+02,-3.8241E-15,1.2681E-14
49+
1.1400E+02,3.6400E+02,2.4758E-14,-2.2285E-15
50+
1.1400E+02,4.1400E+02,-2.9489E-15,-4.4338E-15
51+
1.1400E+02,4.6400E+02,-8.1745E-15,-9.8404E-15
52+
1.6400E+02,4.6400E+02,3.5776E-14,2.2796E-14
53+
1.6400E+02,4.1400E+02,-2.5729E-14,-7.7035E-14
54+
1.6400E+02,3.6400E+02,-3.7585E-14,1.9088E-14
55+
1.6400E+02,3.1400E+02,-3.7116E-14,-1.0737E-14
56+
1.6400E+02,2.6400E+02,-9.6118E-16,2.5668E-14
57+
1.6400E+02,2.1400E+02,-2.5164E-14,3.4926E-15
58+
1.6400E+02,1.6400E+02,3.6228E-15,-5.8737E-15
59+
1.6400E+02,1.1400E+02,4.7331E-14,-9.5260E-15
60+
1.6400E+02,6.4000E+01,-1.2748E-14,-7.0546E-15
61+
1.6400E+02,1.4000E+01,4.1061E-15,-7.1848E-15
62+
2.1400E+02,1.4000E+01,-1.2881E-14,1.3311E-14
63+
2.1400E+02,6.4000E+01,1.1743E-14,6.8009E-16
64+
2.1400E+02,1.1400E+02,3.5518E-15,2.3601E-14
65+
2.1400E+02,1.6400E+02,1.2208E-14,-2.7517E-14
66+
2.1400E+02,2.1400E+02,3.0225E-14,-3.4731E-14
67+
2.1400E+02,2.6400E+02,3.5041E-14,1.4662E-14
68+
2.1400E+02,3.1400E+02,1.5267E-14,1.5042E-14
69+
2.1400E+02,3.6400E+02,2.4440E-14,1.2853E-14
70+
2.1400E+02,4.1400E+02,-7.8362E-15,2.2289E-14
71+
2.1400E+02,4.6400E+02,4.0687E-16,1.4324E-14
72+
2.6400E+02,4.6400E+02,3.9137E-14,1.5827E-14
73+
2.6400E+02,4.1400E+02,2.2804E-14,-1.1630E-15
74+
2.6400E+02,3.6400E+02,2.6821E-14,-1.5820E-14
75+
2.6400E+02,3.1400E+02,5.8236E-14,8.2714E-14
76+
2.6400E+02,2.6400E+02,1.2753E-14,1.3709E-14
77+
2.6400E+02,2.1400E+02,1.2615E-14,-6.8342E-15
78+
2.6400E+02,1.6400E+02,2.9350E-15,4.2982E-14
79+
2.6400E+02,1.1400E+02,-3.6274E-15,2.4950E-14
80+
2.6400E+02,6.4000E+01,-9.3434E-15,1.6646E-14
81+
2.6400E+02,1.4000E+01,1.4911E-14,4.8673E-15
82+
3.1400E+02,1.4000E+01,-9.1787E-15,2.5717E-14
83+
3.1400E+02,6.4000E+01,-4.3543E-14,-6.0627E-14
84+
3.1400E+02,1.1400E+02,2.9071E-14,7.4323E-14
85+
3.1400E+02,1.6400E+02,6.9559E-15,1.4795E-14
86+
3.1400E+02,2.1400E+02,-1.8781E-14,3.5287E-15
87+
3.1400E+02,2.6400E+02,-1.5458E-15,1.0190E-14
88+
3.1400E+02,3.1400E+02,-1.6197E-15,3.5331E-14
89+
3.1400E+02,3.6400E+02,-4.2548E-14,-7.0871E-15
90+
3.1400E+02,4.1400E+02,1.1736E-14,-7.7790E-15
91+
3.1400E+02,4.6400E+02,1.7227E-14,-9.4241E-15
92+
3.6400E+02,4.6400E+02,5.7045E-15,1.0933E-14
93+
3.6400E+02,4.1400E+02,-3.7209E-15,4.7997E-15
94+
3.6400E+02,3.6400E+02,-2.1955E-14,-1.3568E-14
95+
3.6400E+02,3.1400E+02,3.7274E-14,8.7413E-14
96+
3.6400E+02,2.6400E+02,-3.8726E-15,-4.8110E-14
97+
3.6400E+02,2.1400E+02,1.0375E-14,-9.3443E-15
98+
3.6400E+02,1.6400E+02,8.4048E-15,1.0566E-13
99+
3.6400E+02,1.1400E+02,3.2470E-14,-1.2552E-14
100+
3.6400E+02,6.4000E+01,4.5170E-14,3.9189E-14
101+
3.6400E+02,1.4000E+01,-1.6555E-14,2.2183E-15
102+
4.1400E+02,1.4000E+01,4.7226E-15,4.5933E-14
103+
4.1400E+02,6.4000E+01,8.5930E-16,5.9585E-15
104+
4.1400E+02,1.1400E+02,-3.1935E-16,1.3906E-14
105+
4.1400E+02,1.6400E+02,-7.7349E-15,-6.6933E-15
106+
4.1400E+02,2.1400E+02,1.0992E-14,6.5478E-15
107+
4.1400E+02,2.6400E+02,5.0786E-14,-8.2060E-15
108+
4.1400E+02,3.1400E+02,-2.5271E-14,-6.0688E-15
109+
4.1400E+02,3.6400E+02,6.6824E-15,-1.9699E-14
110+
4.1400E+02,4.1400E+02,1.7304E-14,4.9328E-14
111+
4.1400E+02,4.6400E+02,6.2837E-14,3.2880E-15
112+
4.6400E+02,4.6400E+02,1.5316E-14,-2.4425E-14
113+
4.6400E+02,4.1400E+02,-3.2800E-14,-1.0259E-14
114+
4.6400E+02,3.6400E+02,5.9778E-15,-3.2798E-14
115+
4.6400E+02,3.1400E+02,6.2154E-14,6.0765E-15
116+
4.6400E+02,2.6400E+02,1.6092E-14,1.1180E-14
117+
4.6400E+02,2.1400E+02,-1.0120E-14,6.0485E-15
118+
4.6400E+02,1.6400E+02,2.2205E-14,-3.8367E-14
119+
4.6400E+02,1.1400E+02,-9.0637E-16,2.3501E-14
120+
4.6400E+02,6.4000E+01,-6.4216E-15,1.0943E-15
121+
4.6400E+02,1.4000E+01,-1.6362E-14,-2.6982E-14
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<ParameterList>
2+
<Parameter name="subset_size" type="int" value="15" />
3+
<Parameter name="step_size" type="int" value="50" />
4+
<Parameter name="output_folder" type="string" value="./results/" />
5+
<Parameter name="image_folder" type="string" value="../../component/images/" />
6+
<Parameter name="reference_image_index" type="int" value="0" />
7+
<Parameter name="start_image_index" type="int" value="0" />
8+
<Parameter name="end_image_index" type="int" value="0" />
9+
<Parameter name="num_file_suffix_digits" type="int" value="1" />
10+
<Parameter name="image_file_extension" type="string" value=".tif" />
11+
<Parameter name="image_file_prefix" type="string" value="æbärnɃ" />
12+
<Parameter name="correlation_parameters_file" type="string" value="params.xml" />
13+
</ParameterList>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<ParameterList>
2+
<Parameter name="interpolation_method" type="string" value="KEYS_FOURTH" />
3+
<Parameter name="initialization_method" type="string" value="USE_FIELD_VALUES" />
4+
<Parameter name="optimization_method" type="string" value="GRADIENT_BASED" />
5+
<Parameter name="write_exodus_output" type="bool" value="false" />
6+
<Parameter name="enable_translation" type="bool" value="true" />
7+
<Parameter name="enable_rotation" type="bool" value="true" />
8+
<Parameter name="enable_normal_strain" type="bool" value="true" />
9+
<Parameter name="enable_shear_strain" type="bool" value="true" />
10+
<Parameter name="output_delimiter" type="string" value="," />
11+
<Parameter name="omit_output_row_id" type="bool" value="true" />
12+
<!-- Output spec using the old way where the column index had to be specified -->
13+
<ParameterList name="output_spec">
14+
<Parameter name="COORDINATE_X" type="int" value="0" />
15+
<Parameter name="COORDINATE_Y" type="int" value="1" />
16+
<Parameter name="DISPLACEMENT_X" type="int" value="2" />
17+
<Parameter name="DISPLACEMENT_Y" type="int" value="3" />
18+
</ParameterList>
19+
</ParameterList>

0 commit comments

Comments
 (0)