Ask Your Question
0

detect ir led in openCV.

asked 2018-11-12 01:12:51 -0600

Yusha gravatar image

I am currently working on a project assigned from our university, which involves detecting a pen. I am thinking of putting an ir LED on top of that pen, and try to detect with the help of a webcam, but i am stuck at how to filter the background in such a manner so that i could only see that LED. Thanks in advance.

edit retag flag offensive close merge delete

Comments

With an infrared camera, the LED should be the brightest object in the image. You can try blob detection with SimpleBlobDetector class maybe.

Eduardo gravatar imageEduardo ( 2018-11-12 06:59:49 -0600 )edit

@Eduardo thanks for replying, but the problem is filtering the background in such a manner that it only detects my LED, and nothing else. By using an ir camera i could be getting other ir noise in the backgorund. Please let me know if you could help me out with that.

Yusha gravatar imageYusha ( 2018-11-12 10:22:27 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-11-13 07:28:36 -0600

supra56 gravatar image

I try this with my 7 ports hub. And it has blue led power supply.

#!/usr/bin/env python3.4
import cv2
import numpy as np

camera_feed = cv2.VideoCapture(0)

while True:
    _,frame = camera_feed.read()
    #Convert the current frame to HSV
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    #Define the threshold for finding a blue object with hsv
    lower_blue = np.array([110,50,50])
    upper_blue = np.array([130,255,255])

    #Create a binary image, where anything blue appears white and everything else is black
    mask = cv2.inRange(hsv, lower_blue, upper_blue)

    #Get rid of background noise using erosion and fill in the holes using dilation and erode the final image on last time
    element = cv2.getStructuringElement(cv2.MORPH_RECT,(3,3))
    mask = cv2.erode(mask,element, iterations=2)
    mask = cv2.dilate(mask,element,iterations=2)
    mask = cv2.erode(mask,element)

    #Create Contours for all blue objects
    _, contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    maximumArea = 0
    bestContour = None
    for contour in contours:
        currentArea = cv2.contourArea(contour)
        if currentArea > maximumArea:
            bestContour = contour
            maximumArea = currentArea
     #Create a bounding box around the biggest blue object
    if bestContour is not None:
        x,y,w,h = cv2.boundingRect(bestContour)
        cv2.rectangle(frame, (x,y),(x+w,y+h), (0,0,255), 3)
        cv2.circle(frame,(x, y), 2,(0, 255, 0), 20)

    #Show the original camera feed with a bounding box overlayed
    cv2.imshow('frame',frame)
    #Show the contours in a seperate window
    cv2.imshow('mask',mask)
    #Use this command to prevent freezes in the feed
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cv2.destroyAllWindows()
edit flag offensive delete link more

Comments

For green leds.

# green
greenLower = (35,21,62)
greenUpper = (90,255,255)

# yellow
yellowLower = (25, 100, 100)
yellowUpper = (50, 255, 255)
supra56 gravatar imagesupra56 ( 2018-11-13 07:30:18 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-11-12 01:12:51 -0600

Seen: 1,707 times

Last updated: Nov 13 '18