NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


import cv2

import cv2 as cv

import numpy as np

 

kernel = np.ones((5,5),np.uint8)

 

# Take input from webcam

cap = cv2.VideoCapture(0)

 

# Reduce the size of video to 320x240 so rpi can process faster

cap.set(3,320)

cap.set(4,240)

 

def nothing(x):

    pass

# Creating a windows for later use

cv2.namedWindow('HueComp')

cv2.namedWindow('SatComp')

cv2.namedWindow('ValComp')

cv2.namedWindow('closing')

cv2.namedWindow('tracking')

 

 

# Creating track bar for min and max for hue, saturation and value

# You can adjust the defaults as you like

cv2.createTrackbar('hmin', 'HueComp',12,179,nothing)

cv2.createTrackbar('hmax', 'HueComp',37,179,nothing)

 

cv2.createTrackbar('smin', 'SatComp',96,255,nothing)

cv2.createTrackbar('smax', 'SatComp',255,255,nothing)

 

cv2.createTrackbar('vmin', 'ValComp',186,255,nothing)

cv2.createTrackbar('vmax', 'ValComp',255,255,nothing)

 

# My experimental values

# hmn = 12

# hmx = 37

# smn = 145

# smx = 255

# vmn = 186

# vmx = 255

 

 

while(1):

 

    buzz = 0

    _, frame = cap.read()

 

    #converting to HSV

    hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)

    hue,sat,val = cv2.split(hsv)

 

    # get info from track bar and appy to result

    hmn = cv2.getTrackbarPos('hmin','HueComp')

    hmx = cv2.getTrackbarPos('hmax','HueComp')

   

 

    smn = cv2.getTrackbarPos('smin','SatComp')

    smx = cv2.getTrackbarPos('smax','SatComp')

 

 

    vmn = cv2.getTrackbarPos('vmin','ValComp')

    vmx = cv2.getTrackbarPos('vmax','ValComp')

 

    # Apply thresholding

    hthresh = cv2.inRange(np.array(hue),np.array(hmn),np.array(hmx))

    sthresh = cv2.inRange(np.array(sat),np.array(smn),np.array(smx))

    vthresh = cv2.inRange(np.array(val),np.array(vmn),np.array(vmx))

 

    # AND h s and v

    tracking =cv2.bitwise_and(hthresh,cv2.bitwise_and(sthresh,vthresh))

 

    # Some morpholigical filtering

    dilation = cv2.dilate(tracking,kernel,iterations = 1)

    closing = cv2.morphologyEx(dilation, cv2.MORPH_CLOSE, kernel)

    closing = cv2.GaussianBlur(closing,(5,5),0)

 

    # Detect circles using HoughCircles

    circles =cv2.HoughCircles(closing,cv2.HOUGH_GRADIENT,2,120,param1=120,param2=50,minRadius=10,maxRadius=0)

    # circles = np.uint16(np.around(circles))

   

 

    #Draw Circles

    if circles is not None:

            for i in circles[0,:]:

                # If the ball is far, draw it in green

                if int(round(i[2])) < 30:

                    cv2.circle(frame,(int(round(i[0])),int(round(i[1]))),int(round(i[2])),(0,255,0),5)

                    cv2.circle(frame,(int(round(i[0])),int(round(i[1]))),2,(0,255,0),10)

                # else draw it in red

                elif int(round(i[2])) > 35:

                    cv2.circle(frame,(int(round(i[0])),int(round(i[1]))),int(round(i[2])),(0,0,255),5)

                    cv2.circle(frame,(int(round(i[0])),int(round(i[1]))),2,(0,0,

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.