Skip to content

Commit 18f79d1

Browse files
committed
reading raw file thumbnails
1 parent 8f97ee8 commit 18f79d1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/dataset_image_annotator/__main__.py

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44
from typing import Sequence
55

6+
import rawpy
67
from PySide6.QtCore import QFile, QIODevice
78
from PySide6.QtUiTools import QUiLoader
89
from PySide6.QtWidgets import QApplication
@@ -27,10 +28,23 @@ def list_dir_images(path: Path) -> Sequence[Path]:
2728
return files
2829

2930

31+
def get_raw_thumbnail(path: Path):
32+
with rawpy.imread(str(path)) as raw:
33+
try:
34+
thumb = raw.extract_thumb()
35+
except rawpy.LibRawNoThumbnailError:
36+
print('no thumbnail found')
37+
except rawpy.LibRawUnsupportedThumbnailError:
38+
print('unsupported thumbnail')
39+
else:
40+
return thumb
41+
42+
3043
def main():
3144
args = get_parsed_args()
3245
data_root_path = Path(args.data_root)
3346
image_file_paths = list_dir_images(data_root_path)
47+
thumb = get_raw_thumbnail(image_file_paths[0])
3448

3549
app = QApplication(sys.argv)
3650

@@ -51,6 +65,9 @@ def main():
5165

5266
window.show()
5367

68+
with rawpy.imread(image_file_paths[0]) as f:
69+
f.extract_thumb()
70+
5471
sys.exit(app.exec())
5572

5673

0 commit comments

Comments
 (0)