Skip to main content

Red color detection opencv python

#!/usr/bin/python
import cv2
import numpy as np

cap = cv2.VideoCapture(0)
while True:
    _, frame = cap.read()
    hsv = cv2.cvtColor(frame , cv2.COLOR_BGR2HSV)
    l_red = np.array([150,150,50])
    u_red = np.array([180,255,150])

    mask = cv2.inRange(hsv , l_red , u_red)
    res = cv2.bitwise_and(frame , frame , mask = mask)



    cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
        cv2.CHAIN_APPROX_SIMPLE)[-2]
    # print frame
    # print cnts
    center = None
        # only proceed if at least one contour was found
    # if len(cnts) > 0:
        # find the largest contour in the mask, then use
        # it to compute the minimum enclosing circle and
        # centroid
    try:
        areas = [cv2.contourArea(c) for c in cnts]
        max_index = np.argmax(areas)
        # print max_index
        cnt=cnts[max_index]
        x,y,w,h = cv2.boundingRect(cnt)
        print "X = ",x," Y=",y," w=",w," h= ",h
        cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2)
        pass
    except:
        pass
    else:
        pass

        # # only proceed if the radius meets a minimum size
        # if radius > 10:
        #     # draw the circle and centroid on the frame,
        #     # then update the list of tracked points
        #     cv2.circle(frame, (int(x), int(y)), int(radius),
        #         (0, 255, 255), 2)
        #     cv2.circle(frame, center, 5, (0, 0, 255), -1)
    # cnts = cnts[0] if imutils.is_cv2() else cnts[1]
    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break
    cv2.imshow('frame' , frame)
    # cv2.imshow('mask' , mask)
    # cv2.imshow('res' , res)

cv2.destroyAllWindows()
cap.release()







##Subscribe and comment

Comments

Popular posts from this blog

How to install swift in arch linux

IN aur i have tried 3 days off. oh shit no errors and errors finally found this method not appropriate. but till aur errors resolved so this it. Fish shell users: set -x LD_LIBRARY_PATH  "download path" (do not include usr directory ) you have to set variable for everytime you want to run swift but there is a method for universal environmental variable. bash users: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<download path> thats it . this is how you can run swift in any linux machine. till official support announce. thank you. My Apps Android: P Music Player  Find Mechanics near You  (my startup) Please download  it will appreciate. and comment me for improvement.

Python Reads gmail

This is tutorial on how to read gmail emails with python programme : ----------------- #!/usr/bin/python __author__ = 'Robokishan' import email import imaplib import ctypes import getpass mail = imaplib.IMAP4_SSL('imap.gmail.com',993) unm = raw_input("insert Email : ") #pwd = raw_input("insert password : ") pwd = getpass.getpass("input : ") mail.login(unm,pwd) mail.select("INBOX") def loop():    mail.select("INBOX")    n=0    (retcode, messages) = mail.search(None, '(UNSEEN)')    if retcode == 'OK':             for num in messages[0].split() :          #print 'Processing '          n=n+1          print n          typ, data = mail.fetch(num,'(RFC822)')          for response_part in data:             if isinstance(response_part, tuple):                 original = email.message_from_string(response_part[1])                 print original['From']        

All Android Manifest permissions

<uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM"/> <uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLY"/> <uses-permission android:name="android.permission.ACCESS_DRM_CERTIFICATES"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FM_RADIO"/> <uses-permission android:name="android.permission.ACCESS_IMS_CALL_SERVICE"/> <uses-permission android:name="android.permission.ACCESS_INPUT_FLINGER"/> <uses-permission android:name="android.permission.ACCESS_KEYGUARD_SECURE_STORAGE"/> <uses-permission android:name="an