我想将cv2.selectROI函数的坐标导出到JSONlike文件,以便我可以在另一个python脚本中使用它们。我的代码是:
r = cv2.selectROI(img, fromCenter)
print(r)
with open('data.txt','w') as outf:
json.dump({r},outf, indent=4)
我得到的错误如下:
Traceback (most recent call last):
(474, 363, 89, 233)
File "C:/Users/razvanv/PycharmProjects/opencv/SpotDetectionFunction.py", line 51, in <module>
f(parcare)
File "C:/Users/razvanv/PycharmProjects/opencv/SpotDetectionFunction.py", line 16, in f
json.dump({r},outf, indent=4)
File "C:\Users\razvanv\AppData\Local\Programs\Python\Python36-32\lib\json\__init__.py", line 179, in dump
for chunk in iterable:
File "C:\Users\razvanv\AppData\Local\Programs\Python\Python36-32\lib\json\encoder.py", line 437, in _iterencode
o = _default(o)
File "C:\Users\razvanv\AppData\Local\Programs\Python\Python36-32\lib\json\encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'set' is not JSON serializable
您有任何解决方案可以导出此坐标吗? 谢谢!