我们使用的是python3.6和OpenCV。你知道吗
我们试图从一幅图像中的两点得到坐标(x,y)。你知道吗
我们有setFrame
函数来显示图像,如下所示:
def setFrame(self):
global video
num = self.frame_scrollBar.value()
self.video_frame.setScaledContents(True); #QLabel will resize itself to the size of pixmap/image and scroll-bar will get visible.
cvRGBImg = cv2.cvtColor(video[num-1], cv2.COLOR_BGR2RGB) #Convert opencv RGB image to QImage
qimg = QtGui.QImage(cvRGBImg.data,cvRGBImg.shape[1], cvRGBImg.shape[0], QtGui.QImage.Format_RGB888)
qpm = QtGui.QPixmap.fromImage(qimg)
self.video_frame.setPixmap(qpm)
此外,我们还有getPos
函数来获得(x,y)坐标:
def getPos(self, event):
global setPoint
global coords
global video
if setPoint == True:
x = event.pos().x()
y = event.pos().y()
coords.append((x,y))
cv2.circle(video[int(self.frame_3.text())-1],(x,y),3,(0,0,255),-1)
self.setFrame()
if len(coords)==2:
setPoint = False
print (coords[0])
print (coords[1])
self.message()
问题是,当我们点击图像上的一个点时,坐标是不正确的。例如,我们点击一个点a,我们看到该点上方的圆,(x,y)与我们点击的点不对应。你知道吗
我们还尝试使用pygame
获取坐标,但仍然没有成功。你知道吗
我们必须进行某种转变吗?如果我们不使用self.video_frame.setScaledContents(True)
,那么呈现的图像在QPixmap
中显示为移位。
你能帮我们吗?你知道吗
我们找到了解决办法。你知道吗
问题是
QLabel
大小与显示的图像大小不对应。你知道吗QLabel
大小为491x371,图像大小为512x512。所以我们必须转换点击的坐标,比如:所以现在命令
cv2.circle(video[int(self.frame_3.text())-1],(x,y),3,(0,0,255),-1)
将圆设计在正确的位置。你知道吗相关问题 更多 >
编程相关推荐