From 937e978c3cf5ba2b11f60c9622c828885798c268 Mon Sep 17 00:00:00 2001 From: knolax <1339802534.kk@gmail.com> Date: Tue, 17 Jan 2017 17:39:50 +0000 Subject: semifunctional capball and particle detection and differentiation --- doc | 10 ++++++++++ manyballs.jpg | Bin 0 -> 706649 bytes proc.py | 8 +++++--- stallmask.jpg | Bin 130024 -> 75670 bytes stallmasked.jpg | Bin 129759 -> 106008 bytes stallmaskedcon.jpg | Bin 230073 -> 194464 bytes 6 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 manyballs.jpg diff --git a/doc b/doc index e61cd8c..69f33fc 100644 --- a/doc +++ b/doc @@ -45,3 +45,13 @@ blue or red after testing with some other images, i have decided to move circle closeness requirement higher to 35, as i got one very clear picture of th capball that scored a 32%. the diffrence in regularity is not good enough for distinguishing capball from particle.i some more testing with the blue ball and one of them was a false negative. 3 more false positives, also one of the particles was below the cut off area. another false negative red ball at 36%, ut it was really covered up by a lot if stuff. +1/17/2017 + I am finding a new way to detect holes in the ball by masking the image with the cotour to + be differentiated, and then find the area of the countours there, in V values, as a percentage of + the area of the main contour. + I just found out that ret is te threshhold value found, OTSU automatically finds a threshold value between two peaks in the histogram. I want to use this for the first threshold but the re values for hue are not contigous, I will use i just for the red component of BGR. adaptive threshholding takes into consideration lighting conditions, this will be used in the second level maskin +g.More info here:http://docs.opencv.org/trunk/d7/d4d/tutorial_py_thresholding.html + to make a mask from a contour, we simply make an empty image and draw the contours. we then threshhold the v value with adaptive thresholding, my fears about the 0s outside of the mask are unfounded.actually, it passess the entire black region as white. So i will do percentage of average instead. +function used: conmasked = cv2.adaptiveThreshold(conmasked, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 3) +I tried the mean of v in the contour, it only works on close ups, for now i guess we'll use size based ones. +I'm decreasing the minimum size. after decreasing the size to 1000, the number of false negatives decreased. The particle differentiation based on contour percentage works reasonably well when the image is not blurry. I think for balls this will be the final build diff --git a/manyballs.jpg b/manyballs.jpg new file mode 100644 index 0000000..7bd31a9 Binary files /dev/null and b/manyballs.jpg differ diff --git a/proc.py b/proc.py index 7bdef13..607d424 100644 --- a/proc.py +++ b/proc.py @@ -17,8 +17,10 @@ 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)) @@ -28,7 +30,7 @@ cv2.imwrite("stallmasked.jpg",cv2.cvtColor(masked,cv2.COLOR_HSV2BGR)); im2, con, heir = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) v = 0 for i in range(0, len(con)) : - if (cv2.contourArea(con[i]) > 2000) : + if (cv2.contourArea(con[i]) > 1000) : a = cv2.contourArea(con[i]) cv2.drawContours(masked, con, i, (120,255,255), 5) (cx, cy), r = cv2.minEnclosingCircle(con[i]) diff --git a/stallmask.jpg b/stallmask.jpg index 78cde04..60894bd 100644 Binary files a/stallmask.jpg and b/stallmask.jpg differ diff --git a/stallmasked.jpg b/stallmasked.jpg index 055b940..01b13fa 100644 Binary files a/stallmasked.jpg and b/stallmasked.jpg differ diff --git a/stallmaskedcon.jpg b/stallmaskedcon.jpg index 687323d..4b389f9 100644 Binary files a/stallmaskedcon.jpg and b/stallmaskedcon.jpg differ -- cgit v1.1