From 7c87e776e1f5f46f69379a16993cc7ca69d3becd Mon Sep 17 00:00:00 2001 From: jiajie555 Date: Fri, 18 Apr 2025 16:59:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86ffprobe=E4=B8=8Eopencv=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E8=A7=86=E9=A2=91=E6=97=8B=E8=BD=AC=E8=A7=92=E5=BA=A6?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=9D=87=E5=81=9A=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ultralytics/data/loaders.py | 23 +++++++++++++++-------- utils/dataloaders.py | 4 ++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ultralytics/data/loaders.py b/ultralytics/data/loaders.py index 7d82e77..8d9183b 100644 --- a/ultralytics/data/loaders.py +++ b/ultralytics/data/loaders.py @@ -348,14 +348,17 @@ class LoadImagesAndVideos: if rotation == 270: im0 = cv2.rotate(im0, cv2.ROTATE_90_COUNTERCLOCKWISE) ###====================== - if success: - self.frame += 1 - paths.append(path) - imgs.append(im0) - info.append(f"video {self.count + 1}/{self.nf} (frame {self.frame}/{self.frames}) {path}: ") - if self.frame == self.frames: # end of video - self.count += 1 - self.cap.release() + + if self.orientation == 270: + im0 = cv2.rotate(im0, cv2.ROTATE_90_COUNTERCLOCKWISE) # for use if cv2 autorotation is False + + self.frame += 1 + paths.append(path) + imgs.append(im0) + info.append(f"video {self.count + 1}/{self.nf} (frame {self.frame}/{self.frames}) {path}: ") + if self.frame == self.frames: # end of video + self.count += 1 + self.cap.release() else: # Move to the next file if the current video ended or failed to open self.count += 1 @@ -382,6 +385,7 @@ class LoadImagesAndVideos: """Creates a new video capture object for the given path.""" self.frame = 0 self.cap = cv2.VideoCapture(path) + self.orientation = int(self.cap.get(cv2.CAP_PROP_ORIENTATION_META)) # rotation degrees self.fps = int(self.cap.get(cv2.CAP_PROP_FPS)) if not self.cap.isOpened(): raise FileNotFoundError(f"Failed to open video {path}") @@ -404,6 +408,9 @@ class LoadImagesAndVideos: else: return 0 + + + return im def __len__(self): """Returns the number of batches in the object.""" return math.ceil(self.nf / self.bs) # number of files diff --git a/utils/dataloaders.py b/utils/dataloaders.py index 439b1c4..13ad9a4 100644 --- a/utils/dataloaders.py +++ b/utils/dataloaders.py @@ -310,8 +310,8 @@ class LoadImages: im0 = cv2.rotate(im0, cv2.ROTATE_90_COUNTERCLOCKWISE) ###====================== - # if self.orientation == 270: - # im0 = cv2.rotate(im0, cv2.ROTATE_90_COUNTERCLOCKWISE) # for use if cv2 autorotation is False + if self.orientation == 270: + im0 = cv2.rotate(im0, cv2.ROTATE_90_COUNTERCLOCKWISE) # for use if cv2 autorotation is False s = f'video {self.count + 1}/{self.nf} ({self.frame}/{self.frames}) {path}: ' else: