增加了单帧入侵判断及yoloV10
This commit is contained in:
@ -34,6 +34,9 @@ from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, c
|
||||
check_yaml, clean_str, cv2, is_colab, is_kaggle, segments2boxes, unzip_file, xyn2xy,
|
||||
xywh2xyxy, xywhn2xyxy, xyxy2xywhn)
|
||||
from utils.torch_utils import torch_distributed_zero_first
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
|
||||
# Parameters
|
||||
HELP_URL = 'See https://docs.ultralytics.com/yolov5/tutorials/train_custom_data'
|
||||
@ -300,7 +303,13 @@ class LoadImages:
|
||||
ret_val, im0 = self.cap.read()
|
||||
|
||||
self.frame += 1
|
||||
|
||||
##======================
|
||||
'''判断视频是否含旋转信息'''
|
||||
rotation = self.get_rotation(path)
|
||||
if rotation == 270:
|
||||
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
|
||||
s = f'video {self.count + 1}/{self.nf} ({self.frame}/{self.frames}) {path}: '
|
||||
@ -329,6 +338,23 @@ class LoadImages:
|
||||
self.orientation = int(self.cap.get(cv2.CAP_PROP_ORIENTATION_META)) # rotation degrees
|
||||
# self.cap.set(cv2.CAP_PROP_ORIENTATION_AUTO, 0) # disable https://github.com/ultralytics/yolov5/issues/8493
|
||||
|
||||
def get_rotation(self, filename):
|
||||
cmd = [
|
||||
"ffprobe", # 注意是 ffprobe,不是 ffmpeg
|
||||
"-v", "error",
|
||||
"-select_streams", "v:0",
|
||||
"-show_entries", "stream_tags=rotate",
|
||||
"-of", "json",
|
||||
filename
|
||||
]
|
||||
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
if result.returncode == 0:
|
||||
metadata = json.loads(result.stdout)
|
||||
rotation = metadata.get("streams", [{}])[0].get("tags", {}).get("rotate", 0)
|
||||
return int(rotation)
|
||||
else:
|
||||
return 0
|
||||
|
||||
def _cv2_rotate(self, im):
|
||||
# Rotate a cv2 video manually
|
||||
if self.orientation == 0:
|
||||
|
Reference in New Issue
Block a user