我有没有办法在视频中间裁剪以在那部分运行我的车辆检测模型

发布于 2025-02-11 19:03:00 字数 31 浏览 3 评论 0原文

我想仅在视频中心推断我的车辆检测模型。就像您在此

I want to run inference of my vehicle detection model only on the center of a video. like you see in this picture. The red zone is only where I want my model to run. I wanted to know if there's a way for me to do that. to specify a zone for my model to work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没企图 2025-02-18 19:03:00

这是我用于作物的代码,有点有效。我只需要使用我的车辆检测模型来实现它,我将在完成后立即发布

# Import packages
import cv2
import numpy as np

# Open the video
cap = cv2.VideoCapture('test.mp4')

# Initialize frame counter
cnt = 0

# Some characteristics from the original video
w_frame, h_frame = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), 
int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps, frames = cap.get(cv2.CAP_PROP_FPS), cap.get(cv2.CAP_PROP_FRAME_COUNT)

# Here you can define your croping values
x,y,h,w = 0,0,600,1000

# output
fourcc = cv2.VideoWriter_fourcc(*'MP4V')

#fourcc = cv2.cv.CV_FOURCC(*'XVID')

out = cv2.VideoWriter('result.mp4', fourcc, fps, (w, h))


# Now we start
while(cap.isOpened()):
ret, frame = cap.read()

    cnt += 1 # Counting frames

# Avoid problems when video finish
if ret==True:
    # Croping the frame
    crop_frame = frame[y:y+h, x:x+w]

    # Percentage
    xx = cnt *100/frames
    print(int(xx),'%')

    # Saving from the desired frames
    #if 15 <= cnt <= 90:
    #    out.write(crop_frame)

    # I see the answer now. Here you save all the video
    out.write(crop_frame)

    # Just to see the video in real time          
    cv2.imshow('frame',frame)
    cv2.imshow('croped',crop_frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
else:
    break


cap.release()
out.release()  
cv2.destroyAllWindows()

This is the code that I have used for the crop which kinda works. I just need to implement it with my vehicle detection model which I will post right after I finish

# Import packages
import cv2
import numpy as np

# Open the video
cap = cv2.VideoCapture('test.mp4')

# Initialize frame counter
cnt = 0

# Some characteristics from the original video
w_frame, h_frame = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), 
int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps, frames = cap.get(cv2.CAP_PROP_FPS), cap.get(cv2.CAP_PROP_FRAME_COUNT)

# Here you can define your croping values
x,y,h,w = 0,0,600,1000

# output
fourcc = cv2.VideoWriter_fourcc(*'MP4V')

#fourcc = cv2.cv.CV_FOURCC(*'XVID')

out = cv2.VideoWriter('result.mp4', fourcc, fps, (w, h))


# Now we start
while(cap.isOpened()):
ret, frame = cap.read()

    cnt += 1 # Counting frames

# Avoid problems when video finish
if ret==True:
    # Croping the frame
    crop_frame = frame[y:y+h, x:x+w]

    # Percentage
    xx = cnt *100/frames
    print(int(xx),'%')

    # Saving from the desired frames
    #if 15 <= cnt <= 90:
    #    out.write(crop_frame)

    # I see the answer now. Here you save all the video
    out.write(crop_frame)

    # Just to see the video in real time          
    cv2.imshow('frame',frame)
    cv2.imshow('croped',crop_frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
else:
    break


cap.release()
out.release()  
cv2.destroyAllWindows()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文