我有一个PyQt5图形用户界面应用程序.我从相机中读取一个帧,以在其上 Select 一个较小的区域,稍后我只想显示该区域.我正确地 Select 了该区域,并将其存储在QRect中.但当我试图裁剪要显示的帧并稍后进行处理时,显示的实时视频有时会正常工作.但大多数情况下,它看起来就像这张照片上的那样.它变得倾斜了,右角应该是左角.粉红色的圆圈应该在视频的中间,所以它有点错误.
我有这个Worker1类,我在其中处理显示的帧.
class Worker1(QThread):
ImageUpdate = pyqtSignal(QImage)
def __init__(self, canvas, selection):
super().__init__()
self.ThreadActive = True
self.canvas = canvas
self.anim = None
self.selection = selection
def run(self):
Capture = cv.VideoCapture(0)
old_closest_contour = None
d_tresh = 300
P_color = (0, 255, 0)
global i
i = 0
while self.ThreadActive:
i += 1
ret, frame = Capture.read()
if ret:
if self.selection is None or self.selection.isEmpty():
cropped_frame = frame
else:
a = int(self.selection.x())
b = int(self.selection.y())
width = int(self.selection.width())
height = int(self.selection.height())
#print(str(a) + " " + str(b) + " " + str(width) + " " + str(height))
cropped_frame = frame[b: b + height, a: a + width].copy()
#print(cropped_frame.shape[1])
#print(cropped_frame.shape[0])
### other processing lines, those are not relevant in the displaying ###
Image = cv.cvtColor(cropped_frame, cv.COLOR_BGR2RGB)
img = cv.medianBlur(Image, 25)
cv.circle(img, (x, y), r, P_color, 1)
cv.circle(img, (x, y), 4, P_color, -1)
cv.circle(img, point, 0, (255, 0, 255), 10)
ConvertToQtFormat = QImage(img.data, img.shape[1], img.shape[0], QImage.Format_RGB888)
self.ImageUpdate.emit(ConvertToQtFormat)
Capture.release()