如何导入 .py 文件,以便在 kivy 中单击按钮时运行该文件?它说模块名称未定义

08-12 资讯 投稿:惠凝丹
所以,我在一个文件中有 kivy 代码,我试图将我的一个按钮链接到外部 python 文件(我认为这个词是模块?)。我正在尝试导入此文件,但收到错误“NameError:名称'Aruco'未定义”

我正在尝试导入此文件,但收到错误“NameError:名称'Aruco'未定义”Aruco.py 是我要导入的模块的名称。

主要.py

import kivyfrom kivy.app import Appfrom kivy.uix.widget import Widgetfrom kivy.properties import ObjectPropertyfrom kivy.uix.screenmanager import ScreenManager, Screenfrom kivy.lang.builder import Builderimport sqlite3import Arucoclass MainWindow(Screen): passclass InfoWindow(Screen): passclass LocaliseWindow(Screen): passclass WindowManager(ScreenManager): passkv = Builder.load_string("""WindowManager: MainWindow: LocaliseWindow: InfoWindow "DICT_7X7_1000": cv2.aruco.DICT_7X7_1000, "DICT_ARUCO_ORIGINAL": cv2.aruco.DICT_ARUCO_ORIGINAL, "DICT_APRILTAG_16h5": cv2.aruco.DICT_APRILTAG_16h5, "DICT_APRILTAG_25h9": cv2.aruco.DICT_APRILTAG_25h9, "DICT_APRILTAG_36h10": cv2.aruco.DICT_APRILTAG_36h10, "DICT_APRILTAG_36h11": cv2.aruco.DICT_APRILTAG_36h11 corners = markerCorner.reshape((4, 2)) (topLeft, topRight, bottomRight, bottomLeft) = corners topRight = (int(topRight[0]), int(topRight[1])) bottomRight = (int(bottomRight[0]), int(bottomRight[1])) bottomLeft = (int(bottomLeft[0]), int(bottomLeft[1])) topLeft = (int(topLeft[0]), int(topLeft[1])) cv2.line(image, topLeft, topRight, (0, 255, 0), 2) cv2.line(image, topRight, bottomRight, (0, 255, 0), 2) cv2.line(image, bottomRight, bottomLeft, (0, 255, 0), 2) cv2.line(image, bottomLeft, topLeft, (0, 255, 0), 2) cX = int((topLeft[0] + bottomRight[0]) / 2.0) cY = int((topLeft[1] + bottomRight[1]) / 2.0) cv2.circle(image, (cX, cY), 4, (0, 0, 255), -1) cv2.putText(image, str(markerID),(topLeft[0], topLeft[1] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) print("ArUco marker ID: {}".format(markerID)) return markerID return image capture.set(cv2.CAP_PROP_FRAME_WIDTH, 1280) capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 720) height = int(width*(h/w)) img = cv2.resize(img, (width, height), interpolation=cv2.INTER_CUBIC) corners, ids, rejected = cv2.aruco.detectMarkers(img, arucoDict, parameters=arucoParams) detected_markers = aruco_display(corners, ids, rejected, img) cv2.imshow("Image", detected_markers) key = cv2.waitKey(1) 0xFF if key == ord(" "): break cv2.destroyAllWindows() capture.release() return markerID
声明:生活头条网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系admin@gdcyjd.com