Commit f458c65b authored by Lars Bittrich's avatar Lars Bittrich

segmentation.py: adaptation to allow usage of OpenCV 4.0 alongside 3.4

editParticles.py: correctly handle cancelation of Combine and Reassign actions; adaptation to allow usage of OpenCV 4.0 alongside 3.4
analysisview.py: some first restructuring; export dialogs are now QDialogs instead of QWidgets; restructuring of ExcelExport and bugfixes therein; hit quality index export is broken and now set to zero instead wrong numbers
parent 8c55b20a
This diff is collapsed.
......@@ -52,6 +52,8 @@ class ParticleEditor(object):
def combineParticles(self, contourIndices, new_assignment):
if new_assignment == 'other':
new_assignment = self.getNewEntry()
if new_assignment is None:
return
contourIndices = sorted(contourIndices) #we want to keep the contour with lowest index
print('merging contours:', contourIndices)
......@@ -80,7 +82,10 @@ class ParticleEditor(object):
img = np.uint8(cv2.morphologyEx(img, cv2.MORPH_CLOSE, np.ones((3, 3))))
temp, contours, hierarchy = cv2.findContours(img, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
if cv2.__version__ > '3.5':
contours, hierarchy = cv2.findContours(img, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
else:
temp, contours, hierarchy = cv2.findContours(img, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
newContour = contours[0]
stats = self.characterizeParticle(newContour)
......@@ -139,6 +144,8 @@ class ParticleEditor(object):
def reassignParticles(self, contourindices, new_assignment):
if new_assignment == 'other':
new_assignment = self.getNewEntry()
if new_assignment is None:
return
self.createSafetyBackup()
print(f'reassigning indices {contourindices} into {new_assignment}')
......
......@@ -197,7 +197,10 @@ class Segmentation(object):
def erodeConvexDefects(self, thresh, numiter):
thresh = cv2.copyMakeBorder(thresh, 1, 1, 1, 1, 0)
for iterations in range(numiter):
thresh2, contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
if cv2.__version__ > '3.5':
contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
else:
thresh2, contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
hull = cv2.convexHull(cnt, returnPoints = False)
defects = cv2.convexityDefects(cnt, hull)
......@@ -387,7 +390,11 @@ class Segmentation(object):
if return_step=="watershed":
return np.uint8(255*(markers!=0)), 0
temp, contours, hierarchy = cv2.findContours(markers, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
if cv2.__version__ > '3.5':
contours, hierarchy = cv2.findContours(markers, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
else:
temp, contours, hierarchy = cv2.findContours(markers, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
print("contours")
if self.cancelcomputation:
return None, None, None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment