Skip to content

Commit f13c1ef

Browse files
committed
Fix unicode path issue
1 parent 43b7ddc commit f13c1ef

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

gui/dialogs.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import os
55
import numpy as np
6-
import cv2
76
import traceback
87
import logging
98
import open3d as o3d
@@ -700,11 +699,11 @@ def update_img_preview(self):
700699
rgb_path=read_path)
701700

702701
if v == 1:
703-
cv_img = cv2.imread(dest_path)
702+
cv_img = tt.cv_read_all_path(dest_path)
704703

705704
if post_process != 'edge (from rgb)':
706705
undis = tt.undis(cv_img, ir_xml_path)
707-
cv2.imwrite(dest_path, undis)
706+
tt.cv_write_all_path(undis, dest_path)
708707

709708
self.viewer.setPhoto(QtGui.QPixmap(dest_path))
710709
else:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<calibration>
3+
<projection>frame</projection>
4+
<width>640</width>
5+
<height>512</height>
6+
<f>1009.2550324346817</f>
7+
<cx>-13.869239350341358</cx>
8+
<cy>18.927372783525193</cy>
9+
<k1>-0.60468987861228396</k1>
10+
<k2>0.37884919821313828</k2>
11+
<k3>-0.61661475665909271</k3>
12+
<p1>0.0043840778545755138</p1>
13+
<p2>-0.0098188156513866823</p2>
14+
<date>2023-05-30T08:55:51Z</date>
15+
</calibration>

tools/thermal_tools.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def run(self):
122122
# update progress
123123
self.signals.progressed.emit(self.start + iter)
124124
self.signals.messaged.emit(f'Pre-processing image {i}/{nb_im}')
125-
cv_rgb_img = cv2.imread(rgb_path)
125+
cv_rgb_img = cv_read_all_path(rgb_path)
126126

127127
und = undis(cv_rgb_img, rgb_xml_path)
128128
crop = match_rgb(und, self.drone_model)
@@ -135,7 +135,8 @@ def run(self):
135135
new_name = file[:-4] + 'crop.JPG'
136136

137137
dest_path = os.path.join(self.dest_crop_folder, new_name)
138-
cv2.imwrite(dest_path, crop)
138+
139+
cv_write_all_path(crop, dest_path)
139140

140141
self.signals.finished.emit()
141142

@@ -200,6 +201,17 @@ def get_resolution(img_path):
200201

201202

202203
# LENS RELATED METHODS (GENERAL)
204+
def cv_read_all_path(path):
205+
"""
206+
Allows reading image from any kind of unicode character (useful for french accents, for example)
207+
"""
208+
img = cv2.imdecode(np.fromfile(path, dtype=np.uint8), cv2.IMREAD_UNCHANGED)
209+
return img
210+
211+
def cv_write_all_path(img, path):
212+
is_success, im_buf_arr = cv2.imencode(".JPG", img)
213+
im_buf_arr.tofile(path)
214+
203215
def undis(cv_img, xml_path):
204216
def read_matrices(xml_path):
205217
cv_file = cv2.FileStorage(xml_path, cv2.FILE_STORAGE_READ)
@@ -405,12 +417,13 @@ def create_undis_folder(list_ir_paths, drone_model, dest_und_folder):
405417
ir_xml_path = m3t_ir_xml_path
406418

407419
for ir_path in list_ir_paths:
408-
cv_ir_img = cv2.imread(ir_path)
420+
cv_ir_img = cv_read_all_path(ir_path)
409421
cv_und = undis(cv_ir_img, ir_xml_path)
410422
_, file = os.path.split(ir_path)
411423
new_name = file[:-4] + 'undis.JPG'
412424
dest_path = os.path.join(dest_und_folder, new_name)
413-
cv2.imwrite(dest_path, cv_und)
425+
cv_write_all_path(cv_und, dest_path)
426+
414427

415428

416429
def create_rgb_crop_folder(list_rgb_paths, drone_model, scale_percent, dest_crop_folder, progressbar, start, stop):
@@ -419,7 +432,7 @@ def create_rgb_crop_folder(list_rgb_paths, drone_model, scale_percent, dest_crop
419432
for i, rgb_path in enumerate(list_rgb_paths):
420433
iter = i * (stop - start) / nb_im
421434
progressbar.setProperty("value", start + iter)
422-
cv_rgb_img = cv2.imread(rgb_path)
435+
cv_rgb_img = cv_read_all_path(rgb_path)
423436

424437
if drone_model == 'MAVIC2-ENTERPRISE-ADVANCED':
425438
rgb_xml_path = m2t_rgb_xml_path
@@ -611,7 +624,7 @@ def process_one_th_picture(param, drone_model, ir_img_path, dest_path, tmin, tma
611624
img_th_smooth.save(dest_path)
612625
elif post_process == 'edge (from rgb)':
613626
img_thermal.save(dest_path)
614-
cv_ir_img = cv2.imread(dest_path)
627+
cv_ir_img = cv_read_all_path(dest_path)
615628

616629
if drone_model == 'MAVIC2-ENTERPRISE-ADVANCED':
617630
ir_xml_path = m2t_ir_xml_path
@@ -621,7 +634,7 @@ def process_one_th_picture(param, drone_model, ir_img_path, dest_path, tmin, tma
621634
rgb_xml_path = m3t_rgb_xml_path
622635

623636
cv_ir_img = undis(cv_ir_img, ir_xml_path)
624-
cv_match_rgb_img = cv2.imread(rgb_path)
637+
cv_match_rgb_img = cv_read_all_path(rgb_path)
625638
add_lines_from_rgb(cv_ir_img, cv_match_rgb_img, drone_model, dest_path)
626639

627640
# elif post_process == 'superpixel':

0 commit comments

Comments
 (0)