Ask Your Question

szewczukm219's profile - activity

2016-02-08 18:33:24 -0600 asked a question Calculating center of object

Hello, currently I am trying to calculate the center of an object using the following code

import cv2
import numpy as np
vid = cv2.VideoCapture(0)
vid.set(10,.05)

def processVid():
    while(True):
        ret, frame = vid.read()
        hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
        lower_green = np.array([70,200,200])
        upper_green = np.array([90,255,255])
        mask = cv2.inRange(hsv, lower_green, upper_green)
        res = cv2.bitwise_and(frame,frame,mask=mask)
        getPixel(res)
        cv2.imshow('Masked Image',res)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    vid.release()
    cv2.destroyAllWindows()

def getPixel(img):
    for r in range(0,479):
         for c in range(0,639):
              print img[r,c]

processVid()

Currently, this code only prints out the pixel value at the row and column, as I'm having a bit of difficulty determining the best solution to what I'm trying to accomplish. I want this code to take a video feed, apply the designated filters to the video feed and then be able to determine the distance away that the object from the center of the video (i.e. if res is 640x480, I want to find the distance away from pixel @ (320,240)). Here is an example of what my current image looks like, and I want to be able to find the center of that object to the center of the video feed. What I had thought to do was to run through every pixel, and find whether it was black or colored, and then based on that be able to calculate the center. In doing this, it was a slow process (and I mean slow), not to mention I was running this off of a raspberry pi, and it is a video feed so the process would have to be almost instantaneous for accuracy in distance. I'm just curious if there is a built in OpenCV function that does this already? I haven't been able to find any documentation for this yet.

Example image of what code currently displays

2016-02-07 08:49:22 -0600 received badge  Supporter (source)
2016-02-07 08:49:17 -0600 received badge  Scholar (source)
2016-02-06 23:13:06 -0600 asked a question Vision tracking using retroreflective tape

Hello,

I am an FRC programmer, currently assigned with the task of vision processing. My team has not ever done vision processing in the past and it would be very helpful to have vision tracking done for this years challenge. Currently, I am able to take this image image description

and turn it into this, image description

using the code below. I've gotten to this point and am struggling getting the area highlighted (Made out of retroreflective tape) to the point where the processed image (second image) to be a more defined area of color. Currently I am using a usb webcam with a green LED ring around it. I am looking for a little bit of help defining the outlined area in the second image with the green colored bit in the first image.

import cv2
import numpy as np
vid = cv2.VideoCapture(0)
vid.set(10,.05)

while(True):
    ret, frame = vid.read()
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
    lower_green = np.array([40,20,20])
    upper_green = np.array([70,255,255])
    mask = cv2.inRange(hsv, lower_green, upper_green)
    res = cv2.bitwise_and(frame,frame,mask=mask)
    cv2.imshow('orig',frame)
    cv2.imshow('fff',res)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
vid.release()
cv2.destroyAllWindows()