OPENCV旋转相机模式
我想通过中断按钮将相机视图顺时针旋转90度。但是,当我单击一次并取消按钮时,按钮的状态又回到了默认状态。结果,在单击按钮时,相机将旋转以进行实例,然后在While循环中返回默认模式。如何解决这个问题?
这是我的片段:
import cv2
cap = cv2. VideoCapture(0)
while True:
ret, frame = cap.read()
cv2.imshow('null', frame)
if (button):
frame = cv2.rotate(frame, cv2.ROTATE_90_CLOCKWISE)
cv2.imshow('null', frame)
if cv2.waitKey(5) & 0xFF == 27:
break
cap.release()
任何帮助将不胜感激。
I want to rotate the camera view by 90 degree clockwise with an interrupt button. But the button's state goes back to it's default state when I click once and unpress the button. As a result, on clicking the button, the camera rotates for an instance and then goes back to the default mode in the while loop. How to solve this issue?
Here is my snippet:
import cv2
cap = cv2. VideoCapture(0)
while True:
ret, frame = cap.read()
cv2.imshow('null', frame)
if (button):
frame = cv2.rotate(frame, cv2.ROTATE_90_CLOCKWISE)
cv2.imshow('null', frame)
if cv2.waitKey(5) & 0xFF == 27:
break
cap.release()
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用额外的变量 -
rowate = false
- 以通过这种方式保留此状态
从
true true true 但永远不要从false> false
truetrue
false
编辑:
如果下一个按下应该旋转90度(至180),则需要更复杂的代码。它将检查上一个循环中的
is_presse()
是否为false
,并且在当前循环中为true
- 仅在按下按钮长时间按下按钮时仅运行一次时间。这样的东西。
我使用普通
空格
对其进行测试。You should use extra variable -
rotate = False
- to keep this stateThis way it changes
rotate
fromFalse
toTrue
but never fromTrue
toFalse
EDIT:
If next press should rotate another 90 degrees (to 180) then it would need more complex code. It would check if
is_pressed()
in previous loop wasFalse
and in current loop isTrue
- to run it only once when button is pressed long time.Something like this.
I used normal
space
to test it.我会尝试这样的事情,当您按按钮时,它会更改可变button_is_pressed的状态,而仍然没有变化,它会持续旋转图像。
I would try something like this, when you press the button it changes the state of variable button_is_pressed, while still unchanged it keeps rotating image.