我是 python 的初学者,我想问,我有 2 个模块,我想从一个模块获取值。我想获取“ids”值并在另一个模块中使用它在屏幕上打印我试图从导入中调用它但它不起作用,我迷路了
类坐标生成器:KEY_RESET = ord("r") KEY_QUIT = ord("q")
def __init__(self, image, output, color):
self.output = output
self.caption = image
self.color = color
self.image = open_cv.imread(image).copy()
self.click_count = 0
self.ids = 0
self.coordinates = []
open_cv.namedWindow(self.caption, open_cv.WINDOW_GUI_EXPANDED)
open_cv.setMouseCallback(self.caption, self.__mouse_callback)
def generate(self):
while True:
open_cv.imshow(self.caption, self.image)
key = open_cv.waitKey(0)
if key == CoordinatesGenerator.KEY_RESET:
self.image = self.image.copy()
elif key == CoordinatesGenerator.KEY_QUIT:
break
open_cv.destroyWindow(self.caption)
def __mouse_callback(self, event, x, y, flags, params):
if event == open_cv.EVENT_LBUTTONDOWN:
self.coordinates.append((x, y))
self.click_count += 1
if self.click_count >= 4:
self.__handle_done()
elif self.click_count > 1:
self.__handle_click_progress()
open_cv.imshow(self.caption, self.image)
def __handle_click_progress(self):
open_cv.line(self.image, self.coordinates[-2], self.coordinates[-1], (255, 0, 0), 1)
def __handle_done(self):
open_cv.line(self.image,
self.coordinates[2],
self.coordinates[3],
self.color,
1)
open_cv.line(self.image,
self.coordinates[3],
self.coordinates[0],
self.color,
1)
self.click_count = 0
coordinates = np.array(self.coordinates)
翻阅古今
相关分类