# 坐标库
ROI = utils.ROI()
# 路径库
path = utils.Path()
# 选择序列
def hit_button_a():
path.init(tkinter.filedialog.askdirectory(title="Select Folder"))
# 显示路径
if path.img_path != "":
show_path.set("文件路径:" + str(path.img_path)[:-1] + "\n序列总数:" + str(path.sum))
else:
show_path.set("路径错误!")
button_a = tkinter.Button(root, text="选择序列", font=("KaiTi", 15), height=2, command=hit_button_a)
button_a.pack()
canvas.create_window(400, 200, height=20, window=button_a)
# ROI
def hit_button_b():
# 读取首帧图像
first_image = cv2.imread(path.pics_list[0])
# ROI
ROI.init_window(cv2.selectROI(windowName="ROI", img=first_image, showCrosshair=True, fromCenter=False))
cv2.destroyAllWindows()
button_b = tkinter.Button(root, text="标记目标", font=("KaiTi", 15), heigh=2, command=hit_button_b)
button_b.pack()
canvas.create_window(400, 250, height=20, window=button_b)
上面是原来的代码
但是运行之后出现错误
Traceback (most recent call last):
File "E:\Python\lib\tkinter\__init__.py", line 1702, in __call__
return self.func(*args)
File "C:/Users/黄常杰/PycharmProjects/pythonProject2/main.py", line 68, in hit_button_b
ROI.init_window(cv2.selectROI(windowName="ROI", img=first_image, showCrosshair=True, fromCenter=False))
cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-uzca7qz1\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
这一段出现错误提示求助应该怎么解决呜呜呜呜
# ROI
def hit_button_b():
# 读取首帧图像
first_image = cv2.imread(path.pics_list[0])
# ROI
ROI.init_window(cv2.selectROI(windowName="ROI", img=first_image, showCrosshair=True, fromCenter=False))
cv2.destroyAllWindows()