我已经附加了我正在修改的部分代码。我想使用Tkinter创建一个按钮,根据我使用按钮(A或B)的选项,我想在行cv_image = image[:,:,:]
中调整图像大小。
这样做的最佳方法是什么。提前谢谢。
class image_converter:
def __init__(self):
print 'show window'
cv2.namedWindow("Image window", 1)
print 'start bridge and subscribe'
self.bridge = CvBridge()
print Image
self.image_sub = rospy.Subscriber("/MDS_CamServer/camera/image",Image,self.callback)
self.save = False;
self.count=0;
self.X=np.array([[]]);
self.y=np.array([[]]);
self.X_new=np.array([[]]);
self.y_new=np.array([[]]);
def callback(self,data):
try:
image = self.bridge.imgmsg_to_cv2(data, "bgr8")
except CvBridgeError, e:
print e
cv_image = image[:,:,:];
def main(args):
ic = image_converter()
rospy.init_node('image_converter', anonymous=True)
try:
rospy.spin()
except KeyboardInterrupt:
print "Shutting down"
cv2.destroyAllWindows()
if __name__ == '__main__':
main(sys.argv)
答案 0 :(得分:1)
您应创建一个单选按钮,以选择用户想要选择A或B的选项,然后选择将用户重定向到特定宽度
答案 1 :(得分:0)
您可以尝试使用此代码段
self.v1 = IntVar()
Label(master, text="""resize the image in the line with """,justify = LEFT, padx = 20).pack()
Radiobutton(master, text="A",padx = 20, variable=self.v1, value=1).pack(anchor=W)
Radiobutton(master, text="B", padx = 20, variable=self.v1, value=2).pack(anchor=W)
if self.v2.get() == 1:
Imgwidth = 100 #specify it as per A
else:
Imgwidth = 200 #specify it as per B
Imgheight = 100#just specify or use original
image = Image.open(Image_Location)
image = image.resize((Imgheight, Imgwidth), Image.ANTIALIAS) #The (250, 250) is (height, width)
self.pw.pic = ImageTk.PhotoImage(image)