首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有一种方法可以让我在视频的中间进行我的车辆检测模型。

有没有一种方法可以让我在视频的中间进行我的车辆检测模型。
EN

Stack Overflow用户
提问于 2022-06-29 15:53:47
回答 1查看 36关注 0票数 -2

我只想在视频中心对我的车辆检测模型进行推断。就像你在这个图片里看到的。红色区域只是我希望我的模型运行的地方。我想知道是否有办法让我这么做。若要指定模型工作的区域,请执行以下操作。

EN

回答 1

Stack Overflow用户

发布于 2022-06-29 20:40:17

这是我用在作物上的代码。我只需要用我的车辆检测模型来实现它,在我完成之后我就会发布它。

代码语言:javascript
复制
# 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()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72804428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档