如何使用opencv python将填充矩形绘制到视频的每一帧

时间:2021-05-01 18:03:21

标签: python opencv video-processing opencv-python

如果我想在我的视频的每一帧中添加左下角 (x1,y1) 和右上角 (x2,y2) 的黑色填充矩形,我该怎么做?

2 个答案:

答案 0 :(得分:0)

这里是矩形的一般方法

const TRENDING = 'https://api.coingecko.com/api/v3/search/trending'
const Home = () => {
  const [trending, setTrending] = useState<ResponseObject>({})
  useEffect(() => {
    axios.get<ResponseObject>(TRENDING).then((response) => {
      setTrending(response.data)
      console.log(response.data)
    })
  }, [])

  return {trending?.coins?.map((p) => {
          return <div>{p.item.name}
</div>;
}

在我们的例子中使用厚度作为 image = cv2.rectangle(image, start_point, end_point, color, thickness) 来填充矩形

-1

答案 1 :(得分:0)

类似于@muhammad-safwan 所说的,但这也应该有助于您将其放入视频的每一帧中:

您尚未向我们提供任何代码,但我假设它看起来与此类似(其中 cap 是您的视频捕获源):

while True:
    ret, image = cap.read()
    image = cv2.resize(image, (500, 500))
    
    # this is the part to add to your code
    cv2.rectangle(image, (0, 0), (200, 200), (0, 0, 0), -1)

    cv2.imshow("My Video", image)

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

使用 cv2.rectangle(image, (0, 0), (200, 200), (0, 0, 0), -1) 将矩形添加到视频中的每一帧(使用的变量是图像)。