问题描述
如果我想在我的视频的每一帧中添加左下角 (x1,y1) 和右上角 (x2,y2) 的黑色填充矩形,我该怎么做?
解决方法
这里是矩形的一般方法
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
,
类似于@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),-1)
cv2.imshow("My Video",image)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.destroyAllWindows()
使用 cv2.rectangle(image,-1)
将矩形添加到视频中的每一帧(使用的变量是图像)。