Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tuple issue #30

Closed
Jkallehauge opened this issue Oct 24, 2021 · 4 comments · Fixed by #37
Closed

tuple issue #30

Jkallehauge opened this issue Oct 24, 2021 · 4 comments · Fixed by #37

Comments

@Jkallehauge
Copy link

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_contours_coords
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

@Jkallehauge
Copy link
Author

Jkallehauge commented Oct 28, 2021

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(type(contours))
#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

@asim-shrestha
Copy link
Contributor

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 :)

@Renal-Of-Loon
Copy link

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.

@asim-shrestha
Copy link
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants