Closed Jkallehauge closed 2 years ago
Hi all
I changed the tuple to a list in the image_helper.py around line 88 and now it works again - see below.
def find_mask_contours(mask: np.ndarray, approximate_contours: bool): approximation_method = cv.CHAIN_APPROX_SIMPLE if approximate_contours else cv.CHAIN_APPROX_NONE contours, hierarchy = cv.findContours(mask.astype(np.uint8), cv.RETR_TREE, approximation_method)
#print(contours)
contours = list(contours)
# Format extra array out of data
for i, contour in enumerate(contours):
#print(contour)
#print(type(contour))
contours[i] = [[pos[0][0], pos[0][1]] for pos in contour]
hierarchy = hierarchy[0] # Format extra array out of data
return contours, hierarchy
What updates did you make exactly? If you can submit the changes in a pull request I'd be happy to look it over and hopefully get it into the library :)
So I encountered the same issue and it seems to stem from the opencv-python version In opencv-python==4.4.0.46 there is no issue, however in v 4.5.4.60 you encounter this "tuple issue".
I haven't dug into it beyond this since I can freely change versions without drawback, but figured this might help narrow down the issue.
Thanks @Renal-Of-Loon, perhaps opencv changed datatypes in a more recent version. #35 has the same fix you mentioned @Jkallehauge, we will get that in by Friday this week. Thanks for bring it up!
Hi rt_Utils authors
Thanks for a great tool !
I had it working fine but made some updates and now I get som format issues ( tuples). I am adding the error message here - hope you can help :)
Skipping empty mask layer Skipping empty mask layer Skipping empty mask layer Skipping empty mask layer Skipping empty mask layer Skipping empty mask layer Traceback (most recent call last):
File "", line 1, in
rtstruct.add_roi(mask=mask_3d_bool, color=json.loads(strct_color1[strnum-1]), name=strct_names1[strnum-1])
File "C:\Users\jeskal\Anaconda3\lib\site-packages\rt_utils\rtstruct.py", line 59, in add_roi self.ds.ROIContourSequence.append(ds_helper.create_roi_contour(roi_data, self.series_data))
File "C:\Users\jeskal\Anaconda3\lib\site-packages\rt_utils\ds_helper.py", line 144, in create_roi_contour roi_contour.ContourSequence = create_contour_sequence(roi_data, series_data)
File "C:\Users\jeskal\Anaconda3\lib\site-packages\rt_utils\ds_helper.py", line 157, in create_contour_sequence contours_coords = get_contours_coords(roi_data, series_data)
File "C:\Users\jeskal\Anaconda3\lib\site-packages\rt_utils\image_helper.py", line 64, in get_contourscoords contours, = find_mask_contours(mask_slice, roi_data.approximate_contours)
File "C:\Users\jeskal\Anaconda3\lib\site-packages\rt_utils\image_helper.py", line 87, in find_mask_contours contours[i] = [[pos[0][0], pos[0][1]] for pos in contour]
TypeError: 'tuple' object does not support item assignment