将ffprobe与opencv判断视频旋转角度信息均做判断
This commit is contained in:
@ -348,14 +348,17 @@ class LoadImagesAndVideos:
|
|||||||
if rotation == 270:
|
if rotation == 270:
|
||||||
im0 = cv2.rotate(im0, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
im0 = cv2.rotate(im0, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
||||||
###======================
|
###======================
|
||||||
if success:
|
|
||||||
self.frame += 1
|
if self.orientation == 270:
|
||||||
paths.append(path)
|
im0 = cv2.rotate(im0, cv2.ROTATE_90_COUNTERCLOCKWISE) # for use if cv2 autorotation is False
|
||||||
imgs.append(im0)
|
|
||||||
info.append(f"video {self.count + 1}/{self.nf} (frame {self.frame}/{self.frames}) {path}: ")
|
self.frame += 1
|
||||||
if self.frame == self.frames: # end of video
|
paths.append(path)
|
||||||
self.count += 1
|
imgs.append(im0)
|
||||||
self.cap.release()
|
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:
|
else:
|
||||||
# Move to the next file if the current video ended or failed to open
|
# Move to the next file if the current video ended or failed to open
|
||||||
self.count += 1
|
self.count += 1
|
||||||
@ -382,6 +385,7 @@ class LoadImagesAndVideos:
|
|||||||
"""Creates a new video capture object for the given path."""
|
"""Creates a new video capture object for the given path."""
|
||||||
self.frame = 0
|
self.frame = 0
|
||||||
self.cap = cv2.VideoCapture(path)
|
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))
|
self.fps = int(self.cap.get(cv2.CAP_PROP_FPS))
|
||||||
if not self.cap.isOpened():
|
if not self.cap.isOpened():
|
||||||
raise FileNotFoundError(f"Failed to open video {path}")
|
raise FileNotFoundError(f"Failed to open video {path}")
|
||||||
@ -404,6 +408,9 @@ class LoadImagesAndVideos:
|
|||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return im
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
"""Returns the number of batches in the object."""
|
"""Returns the number of batches in the object."""
|
||||||
return math.ceil(self.nf / self.bs) # number of files
|
return math.ceil(self.nf / self.bs) # number of files
|
||||||
|
@ -310,8 +310,8 @@ class LoadImages:
|
|||||||
im0 = cv2.rotate(im0, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
im0 = cv2.rotate(im0, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
||||||
###======================
|
###======================
|
||||||
|
|
||||||
# if self.orientation == 270:
|
if self.orientation == 270:
|
||||||
# im0 = cv2.rotate(im0, cv2.ROTATE_90_COUNTERCLOCKWISE) # for use if cv2 autorotation is False
|
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}: '
|
s = f'video {self.count + 1}/{self.nf} ({self.frame}/{self.frames}) {path}: '
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user