diff options
author | knolax <1339802534.kk@gmail.com> | 2017-01-17 17:00:51 +0000 |
---|---|---|
committer | knolax <1339802534.kk@gmail.com> | 2017-01-17 17:00:51 +0000 |
commit | faab284f1b0fae2e1ef630c447a298e73c840953 (patch) | |
tree | da19e7d92421cd792c409bff60ea27f03d3c16c1 | |
parent | 4788300a8787c901f7d1bdec46d3c2553357736e (diff) |
tried different method for differentiating between particles and capballs. Failed
-rw-r--r-- | proc.py | 43 |
1 files changed, 19 insertions, 24 deletions
@@ -17,8 +17,12 @@ h,s,v = cv2.split(himg) #blue is 195-135, 40? really that much? #hue only testing, not very effective. # better with saturation -thresh = cv2.bitwise_and(cv2.bitwise_or(thresh(h,0,10),thresh(h,169,180)), thresh(s,60,255)) -#thresh = cv2.bitwise_and(thresh(h,95,135), thresh(s,60,255)) + +#red +#thresh = cv2.bitwise_and(cv2.bitwise_or(thresh(h,0,10),thresh(h,169,180)), thresh(s,60,255)) +#blue +thresh = cv2.bitwise_and(thresh(h,95,135), thresh(s,60,255)) + #thresh = cv2.GaussianBlur(thresh,(29,29),0,0,cv2.BORDER_REFLECT_101) cv2.imwrite("stallmask.jpg",thresh); mask = cv2.merge((thresh,thresh,thresh)) @@ -26,7 +30,8 @@ masked = cv2.bitwise_and(himg, mask); cv2.imwrite("stallmasked.jpg",cv2.cvtColor(masked,cv2.COLOR_HSV2BGR)); #only takes 1 cannel arrays? im2, con, heir = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) -v = 0 +#number of contours above certain size +vc = 0 for i in range(0, len(con)) : if (cv2.contourArea(con[i]) > 2000) : a = cv2.contourArea(con[i]) @@ -37,32 +42,22 @@ for i in range(0, len(con)) : cv2.circle(masked, c,int(r), (150,255,255), 5) if (p < .35) : print("yee") - #find find frst child - #her in list mode returns the array inside of another array - if ( heir[0][i][2] != -1 ): - j = heir[0][i][2] - while (j != -1) : - cv2.drawContours(masked, con, j, (160,255,255), 3) - cp = 0 - cp = cp + cv2.contourArea(con[j]) - j = heir[0][j][0] - cp = cp/a - else : - cp = 0 - print ("child area perc") - print(cp) - if (cp > 0.0005) : - cv2.putText(masked, "p", c, cv2.FONT_HERSHEY_PLAIN, 10, (0,255,255),cv2.LINE_AA) - else : - cv2.putText(masked, 'c', c, cv2.FONT_HERSHEY_PLAIN, 10, (0,255,255),cv2.LINE_AA) - + conmask = numpy.zeros(v.shape, numpy.uint8) + cv2.drawContours(conmask, con, i, (255), cv2.FILLED) + conmasked = cv2.bitwise_and(v, conmask) + meanconmasked = conmasked.sum().sum() / a + print(meanconmasked) + ret, conmasked = cv2.threshold(conmasked, meanconmasked, 255, cv2.THRESH_BINARY_INV) + cv2.imwrite("conmasked" + str(i) + ".jpg",cv2.merge((conmasked,conmasked,conmasked))) + im2, rcon, rheir = cv2.findContours(conmasked, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) + cv2.drawContours(masked, rcon, -1, (50, 255, 255),2) print(p) - v = v + 1 + vc = vc + 1 else : cv2.drawContours(masked, con, i, (80,255,255), 1) cv2.imwrite("stallmaskedcon.jpg",cv2.cvtColor(masked,cv2.COLOR_HSV2BGR)) print("properly sized contours") -print(v) +print(vc) print("all contours") print(len(con)) |