Detection, sorting,
Hello I've reworked the photos with a range-detector imutils
how to detect good, round whole white, without those distorted.
Thanks ;-)
Hello I've reworked the photos with a range-detector imutils
how to detect good, round whole white, without those distorted.
Thanks ;-)
Try this. You may modified to suit your need.
#!/usr/bin/python3.7.3
#OpenCV 4.1.2, Raspberry pi 3/3b/4, Buster ver10
#Date: 2nd February, 2019
import cv2
img = cv2.imread('bean1.jpg')
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 85, 255, 0)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
cv2.drawContours(img, contours, -1, (255, 255, 255), cv2.FILLED)
cv2.drawContours(imgray, contours, -1, (255, 255, 255), cv2.FILLED)
cv2.imshow('Image', img)
cv2.imshow('Image GRAY', imgray)
cv2.waitKey(0)
cv2.destroyAllWindows()
Output Image:
Output Imgray:
Thank you for your answer.
how do you connect the codes below to detect from a movie ?
detection code :
import numpy as np import cv2 img = cv2.imread('new2.png') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) blurred = cv2.medianBlur(gray, 9) _filter = cv2.bilateralFilter(blurred, 5, 75, 75) adap_thresh = cv2.adaptiveThreshold(_filter, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 21, 0) element = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3)) dilated = cv2.dilate(adap_thresh, element, iterations=1) # blob detection params = cv2.SimpleBlobDetector_Params() params.filterByColor = False params.minThreshold = 65 params.maxThreshold = 93 params.blobColor = 0 params.minArea = 800 params.maxArea = 5000 params.filterByCircularity = False params.filterByConvexity = True params.minCircularity =.4 params.maxCircularity = 1 det = cv2.SimpleBlobDetector_create(params) keypts = det.detect(dilated) im_with_keypoints = cv2.drawKeypoints(dilated, keypts, np.array([]), (0, 0, 255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) res = cv2.drawKeypoints(img, keypts, np.array([]), (0, 0, 255 ), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) i = 0 for kp in keypts: print("(%f,%f)"%(kp.pt[0],kp.pt[1])) i+=1 cv2.rectangle(res,(int(kp.pt[0]),int(kp.pt[1])),(int(kp.pt[0])+1,int(kp.pt[1])+1),(0,255,0),2) #cv2.imshow("Keypoints", im_with_keypoints) cv2.imshow("RES", res) cv2.waitKey(0)`
and:
import cv2 import numpy as np cap = cv2.VideoCapture('film.wmv') while(1): # Take each frame _, frame = cap.read() # Convert BGR to HSV hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # define range of blue color in HSV lower_blue = np.array([10,50,190]) upper_blue = np.array([145,255,255]) # Threshold the HSV image to get only blue colors mask = cv2.inRange(hsv, lower_blue, upper_blue) # Bitwise-AND mask and original image res = cv2.bitwise_and(frame,frame, mask= mask) cv2.imshow('frame',frame) cv2.imshow('mask',mask) #cv2.imshow('res',res) k = cv2.waitKey(5) & 0xFF if k == 27: break cv2.destroyAllWindows()
sort:
Asked: 2020-01-30 16:17:24 -0600
Seen: 546 times
Last updated: Feb 04 '20
imutils is off topic