增加了单帧入侵判断及yoloV10
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -19,6 +19,8 @@ from ultralytics.data.utils import IMG_FORMATS, VID_FORMATS
|
||||
from ultralytics.utils import LOGGER, is_colab, is_kaggle, ops
|
||||
from ultralytics.utils.checks import check_requirements
|
||||
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
@dataclass
|
||||
class SourceTypes:
|
||||
@ -340,6 +342,12 @@ class LoadImagesAndVideos:
|
||||
|
||||
if success:
|
||||
success, im0 = self.cap.retrieve()
|
||||
##======================
|
||||
'''判断视频是否含旋转信息'''
|
||||
rotation = self.get_rotation(path)
|
||||
if rotation == 270:
|
||||
im0 = cv2.rotate(im0, cv2.ROTATE_90_COUNTERCLOCKWISE)
|
||||
###======================
|
||||
if success:
|
||||
self.frame += 1
|
||||
paths.append(path)
|
||||
@ -355,6 +363,7 @@ class LoadImagesAndVideos:
|
||||
self.cap.release()
|
||||
if self.count < self.nf:
|
||||
self._new_video(self.files[self.count])
|
||||
|
||||
else:
|
||||
self.mode = "image"
|
||||
im0 = cv2.imread(path) # BGR
|
||||
@ -378,6 +387,23 @@ class LoadImagesAndVideos:
|
||||
raise FileNotFoundError(f"Failed to open video {path}")
|
||||
self.frames = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT) / self.vid_stride)
|
||||
|
||||
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 __len__(self):
|
||||
"""Returns the number of batches in the object."""
|
||||
return math.ceil(self.nf / self.bs) # number of files
|
||||
|
Reference in New Issue
Block a user