diff --git a/pdm.lock b/pdm.lock index 73d598d..a2f5696 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,11 +5,22 @@ groups = ["default"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:22e7fb6be688755243be4decdc34c7a192d0929d9c4e6e62980ee8a44a8f2bc1" +content_hash = "sha256:f6e9aeeb24f366560659a66700c5d5a228c427ef73f5f849ef55242aad81d427" [[metadata.targets]] requires_python = "==3.12.*" +[[package]] +name = "et-xmlfile" +version = "1.1.0" +requires_python = ">=3.6" +summary = "An implementation of lxml.xmlfile for the standard library" +groups = ["default"] +files = [ + {file = "et_xmlfile-1.1.0-py3-none-any.whl", hash = "sha256:a2ba85d1d6a74ef63837eed693bcb89c3f752169b0e3e7ae5b16ca5e1b3deada"}, + {file = "et_xmlfile-1.1.0.tar.gz", hash = "sha256:8eb9e2bc2f8c97e37a2dc85a09ecdcdec9d8a396530a6d5a33b30b9a92da0c5c"}, +] + [[package]] name = "numpy" version = "2.1.1" @@ -58,6 +69,45 @@ files = [ {file = "opencv_python-4.10.0.84-cp37-abi3-win_amd64.whl", hash = "sha256:32dbbd94c26f611dc5cc6979e6b7aa1f55a64d6b463cc1dcd3c95505a63e48fe"}, ] +[[package]] +name = "openpyxl" +version = "3.1.5" +requires_python = ">=3.8" +summary = "A Python library to read/write Excel 2010 xlsx/xlsm files" +groups = ["default"] +dependencies = [ + "et-xmlfile", +] +files = [ + {file = "openpyxl-3.1.5-py2.py3-none-any.whl", hash = "sha256:5282c12b107bffeef825f4617dc029afaf41d0ea60823bbb665ef3079dc79de2"}, + {file = "openpyxl-3.1.5.tar.gz", hash = "sha256:cf0e3cf56142039133628b5acffe8ef0c12bc902d2aadd3e0fe5878dc08d1050"}, +] + +[[package]] +name = "pandas" +version = "2.2.3" +requires_python = ">=3.9" +summary = "Powerful data structures for data analysis, time series, and statistics" +groups = ["default"] +dependencies = [ + "numpy>=1.22.4; python_version < \"3.11\"", + "numpy>=1.23.2; python_version == \"3.11\"", + "numpy>=1.26.0; python_version >= \"3.12\"", + "python-dateutil>=2.8.2", + "pytz>=2020.1", + "tzdata>=2022.7", +] +files = [ + {file = "pandas-2.2.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:b1d432e8d08679a40e2a6d8b2f9770a5c21793a6f9f47fdd52c5ce1948a5a8a9"}, + {file = "pandas-2.2.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a5a1595fe639f5988ba6a8e5bc9649af3baf26df3998a0abe56c02609392e0a4"}, + {file = "pandas-2.2.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:5de54125a92bb4d1c051c0659e6fcb75256bf799a732a87184e5ea503965bce3"}, + {file = "pandas-2.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fffb8ae78d8af97f849404f21411c95062db1496aeb3e56f146f0355c9989319"}, + {file = "pandas-2.2.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:6dfcb5ee8d4d50c06a51c2fffa6cff6272098ad6540aed1a76d15fb9318194d8"}, + {file = "pandas-2.2.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:062309c1b9ea12a50e8ce661145c6aab431b1e99530d3cd60640e255778bd43a"}, + {file = "pandas-2.2.3-cp312-cp312-win_amd64.whl", hash = "sha256:59ef3764d0fe818125a5097d2ae867ca3fa64df032331b7e0917cf5d7bf66b13"}, + {file = "pandas-2.2.3.tar.gz", hash = "sha256:4f18ba62b61d7e192368b84517265a99b4d7ee8912f8708660fb4a366cc82667"}, +] + [[package]] name = "pyside6" version = "6.7.3" @@ -109,6 +159,30 @@ files = [ {file = "PySide6_Essentials-6.7.3-cp39-abi3-win_amd64.whl", hash = "sha256:f0950fcdcbcd4f2443336dc6a5fe692172adc225f876839583503ded0ab2f2a7"}, ] +[[package]] +name = "python-dateutil" +version = "2.9.0.post0" +requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" +summary = "Extensions to the standard Python datetime module" +groups = ["default"] +dependencies = [ + "six>=1.5", +] +files = [ + {file = "python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3"}, + {file = "python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"}, +] + +[[package]] +name = "pytz" +version = "2024.2" +summary = "World timezone definitions, modern and historical" +groups = ["default"] +files = [ + {file = "pytz-2024.2-py2.py3-none-any.whl", hash = "sha256:31c7c1817eb7fae7ca4b8c7ee50c72f93aa2dd863de768e1ef4245d426aa0725"}, + {file = "pytz-2024.2.tar.gz", hash = "sha256:2aa355083c50a0f93fa581709deac0c9ad65cca8a9e9beac660adcbd493c798a"}, +] + [[package]] name = "shiboken6" version = "6.7.3" @@ -121,3 +195,36 @@ files = [ {file = "shiboken6-6.7.3-cp39-abi3-manylinux_2_31_aarch64.whl", hash = "sha256:f0dd635178e64a45be2f84c9f33dd79ac30328da87f834f21a0baf69ae210e6e"}, {file = "shiboken6-6.7.3-cp39-abi3-win_amd64.whl", hash = "sha256:5f29325dfa86fde0274240f1f38e421303749d3174ce3ada178715b5f4719db9"}, ] + +[[package]] +name = "six" +version = "1.16.0" +requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" +summary = "Python 2 and 3 compatibility utilities" +groups = ["default"] +files = [ + {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, + {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, +] + +[[package]] +name = "tzdata" +version = "2024.2" +requires_python = ">=2" +summary = "Provider of IANA time zone data" +groups = ["default"] +files = [ + {file = "tzdata-2024.2-py2.py3-none-any.whl", hash = "sha256:a48093786cdcde33cad18c2555e8532f34422074448fbc874186f0abd79565cd"}, + {file = "tzdata-2024.2.tar.gz", hash = "sha256:7d85cc416e9382e69095b7bdf4afd9e3880418a2413feec7069d533d6b4e31cc"}, +] + +[[package]] +name = "xlrd" +version = "2.0.1" +requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" +summary = "Library for developers to extract data from Microsoft Excel (tm) .xls spreadsheet files" +groups = ["default"] +files = [ + {file = "xlrd-2.0.1-py2.py3-none-any.whl", hash = "sha256:6a33ee89877bd9abc1158129f6e94be74e2679636b8a205b43b85206c3f0bbdd"}, + {file = "xlrd-2.0.1.tar.gz", hash = "sha256:f72f148f54442c6b056bf931dbc34f986fd0c3b0b6b5a58d013c9aef274d0c88"}, +] diff --git a/pyproject.toml b/pyproject.toml index 183727a..b31d5ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,9 @@ dependencies = [ "pyside6>=6.7.3", "opencv-python>=4.10.0.84", "numpy>=2.1.1", + "pandas>=2.2.3", + "openpyxl>=3.1.5", + "xlrd>=2.0.1", ] requires-python = "==3.12.*" readme = "README.md" @@ -20,4 +23,4 @@ distribution = false [tool.pdm.scripts] main = "python src/esd_bleeding_view_tool/__init__.py" -nox = "python src/esd_bleeding_view_tool/non_ui.py" \ No newline at end of file +nox = "python src/esd_bleeding_view_tool/core.py" \ No newline at end of file diff --git a/src/esd_bleeding_view_tool/core.py b/src/esd_bleeding_view_tool/core.py new file mode 100644 index 0000000..f43788d --- /dev/null +++ b/src/esd_bleeding_view_tool/core.py @@ -0,0 +1,66 @@ +import os +import cv2 +import pandas as pd +import re + +video_dir = "raw/video/王传林.mp4" +mark_dir = "raw/mark/ESD-Bleeding-标注.xlsx" +interval = 30 + +def convert_video(videoname): + capture = cv2.VideoCapture(videoname) + total_frames = int(capture.get(cv2.CAP_PROP_FRAME_COUNT)) + if capture.isOpened(): + frame_counter = 0 + if not os.path.exists("temp/"): + os.makedirs("temp/") + while True: + ret, img = capture.read() # img 就是一帧图片 + if frame_counter % interval == 0: + cv2.imwrite("temp/"+str(frame_counter)+".jpg", img) + frame_counter += 1 + + if not ret: + break # 当获取完最后一帧就结束 + else: + print('视频打开失败!') + +class Video: + def __init__(self, video_dir): + self.video_dir = video_dir + capture = cv2.VideoCapture(video_dir) + if capture.isOpened(): + self.total_frames = int(capture.get(cv2.CAP_PROP_FRAME_COUNT)) + self.video = capture + else: + self.video = None + def read_frame(self, frame_num): + cap = self.video + cap.set(cv2.CAP_PROP_POS_FRAMES, frame_num) + ret, img=cap.read() + if ret: + return img + else: + return None + +class Mark: + def __init__(self, mark_dir, sheet_name): + self.df = pd.read_excel(mark_dir, sheet_name=sheet_name) + col_name = self.df.columns.tolist() + self.method = col_name[1:] + self.frame = self.df.loc[:,col_name[0]] + self.total_frame = len(self.frame) + + def read(self, number): + line = self.df.loc[number,:] + rt = re.findall(r'\d+', line.iloc[0]) + if len(rt) > 0: + return (int(rt[0]), line[self.method[0]:]) + else: + return None + + +if __name__ == "__main__": + mark = Mark(mark_dir, "王传林") + frame, method = mark.read(1) + print(int(frame),method) \ No newline at end of file diff --git a/src/esd_bleeding_view_tool/non_ui.py b/src/esd_bleeding_view_tool/non_ui.py deleted file mode 100644 index c1c5caa..0000000 --- a/src/esd_bleeding_view_tool/non_ui.py +++ /dev/null @@ -1,21 +0,0 @@ -import cv2 - -video_dir = "raw/video/王传林.mp4" -mark_dir = "raw/mark/ESD-Bleeding-标注.xlsx" - -def convert_video(videoname): - capture = cv2.VideoCapture(videoname) - if capture.isOpened(): - frame_counter = 0 - while True: - ret, img = capture.read() # img 就是一帧图片 - if frame_counter % 30 == 0: - cv2.imwrite("temp/"+str(frame_counter)+".jpg", img) - frame_counter += 1 - - if not ret:break # 当获取完最后一帧就结束 - else: - print('视频打开失败!') - -if __name__ == "__main__": - convert_video(video_dir) \ No newline at end of file