Ask Your Question
2

Detection, sorting,

asked 2020-01-30 16:17:24 -0600

Mialek gravatar image

updated 2020-10-06 12:06:26 -0600

Hello I've reworked the photos with a range-detector imutils image description image description

how to detect good, round whole white, without those distorted.

Thanks ;-)

edit retag flag offensive close merge delete

Comments

imutils is off topic

LBerger gravatar imageLBerger ( 2020-01-31 01:38:33 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2020-02-01 22:47:32 -0600

supra56 gravatar image

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:

image description

Output Imgray:

image description

edit flag offensive delete link more
1

answered 2020-02-03 11:48:53 -0600

Mialek gravatar image

updated 2020-02-04 09:30:15 -0600

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: image description

edit flag offensive delete link more

Comments

1

@Mialek. This is not answer. You're simply to make new post. You can delete your answer. Remove single quote.

cv2.waitKey(0)`

to

cv2.waitKey(0)

Change:

cap = cv2.VideoCapture('film.wmv')

to

cap = cv2.VideoCapture(0)
supra56 gravatar imagesupra56 ( 2020-02-03 12:14:49 -0600 )edit

Thanks for your answer :)

The detection program works on the photos, and I want it to work on the HSV mask of the video.

how to do this ;D I want to make a seed sorter, All white is good. How do you think it'll work? Thanks ;)

Mialek gravatar imageMialek ( 2020-02-03 14:00:00 -0600 )edit

and I want it to work on the HSV mask of the video. Which code are you talking about first or second? But you said that you wanted create video something like move?

supra56 gravatar imagesupra56 ( 2020-02-03 21:24:04 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-01-30 16:17:24 -0600

Seen: 546 times

Last updated: Feb 04 '20