Ask Your Question

luketheduke's profile - activity

2020-10-06 11:42:30 -0500 received badge  Notable Question (source)
2017-04-05 10:02:22 -0500 received badge  Popular Question (source)
2016-01-23 09:52:35 -0500 commented question Python & OpenCV

In your code you've copied it twice... You may want to remove the first copy. One thing to try: remove this line and run the code cv2.namedWindow('image', cv2.WINDOW_NORMAL) I've ran the code without this line fine.

2016-01-23 08:02:56 -0500 asked a question Beaglebone Opencv: throws error and timeout

Hi All, I am running OpenCV on a Beaglebone Black with Ubuntu. After I installed it I tried importing it into python. That all worked so I tried to capture video from a USB Webcam. I can run the command cap = cv2.VideoCapture(0) but when I then run ret, frame = it sits there for thirty seconds and then prints all this out:

select timeout
select timeout
OpenCV Error: Assertion failed (total() == 0 || data != NULL) in Mat, file /home/ubuntu/opencv/modules/core/include/opencv2/core/mat.inl.hpp, line 410
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
cv2.error: /home/ubuntu/opencv/modules/core/include/opencv2/core/mat.inl.hpp:410: error: (-215) total() == 0 || data != NULL in function Mat

Everything I've searched for has come up empty, any ideas? Thanks,

2015-12-30 17:27:58 -0500 received badge  Student (source)
2015-03-05 20:02:27 -0500 received badge  Scholar (source)
2015-03-05 14:27:01 -0500 commented question Detecting a water bottle in video stream C++

I didn't. I tried feeding it various 2d images of the same brand water bottle to no avail. Of all of my tests with different parts of the bottle to match, less than 10% of the matching points landed on the bottle and less than 2% on the same location of the bottle. I am still trying to figure out how to recognize it. Due to the schedule for this project, any and all ideas or thought, especially answers, are appreciated. Also could could I use a depth image from a Kinect to isolate the objects as they are the nearest things in the foreground.

2015-03-05 09:00:02 -0500 received badge  Teacher (source)
2015-03-04 18:39:29 -0500 commented question Detecting a water bottle in video stream C++

I got the example to work but it is not zeroing in on the object. Of the 50 odd points it find only 10 or so are on the 2 bottles. Is this normal?

2015-03-04 16:31:30 -0500 answered a question Detect open door with traincascade?

There are multiple solutions:

  1. First You could try using a color mask to see if the black door is present.

  2. You could also wire a light connected to a switch which closes when the door is open. That would also use a color mask.

  3. Lastly you could just not use OpenCV at all and use a laser connected to a switch as described above and use a Arduino with a light sensor to see if the door is open.

Hope that helps!

2015-03-04 16:18:59 -0500 asked a question Detecting a water bottle in video stream C++

Hi All, I am doing a robotics competition and I need to figure out how to locate a standard water bottle in a video stream and give the location of it on the screen. I have some code for shape detection but it hasn't located the bottles when I feed it an image of it. The bottle is exactly the same as this one, 19.9 fl oz absopure brand Here Any ideas or thoughts are appreciated.

Thanks, L

2015-02-26 14:54:00 -0500 received badge  Necromancer (source)
2015-02-26 14:54:00 -0500 received badge  Self-Learner (source)
2015-02-26 11:43:29 -0500 answered a question Finding coordinates of face in Python[Updated]

I figured it out. I can just isolate the variables x1 and y1 in the for loop towards the bottom and I get my location... Thanks for all the help guys!

2015-02-26 11:40:33 -0500 commented answer Graphical Implementations of OpenCV

When I install it on Ubuntu and run nothing happens when I load localhost:9000. It loads the html but it is just a blank page. When I open the html file I can make code but it doesn't run the code or load anything. Any ideas?

2015-01-11 01:36:34 -0500 asked a question Graphical Implementations of OpenCV

Hi all, I am wanting to use opencv on my robot but the coding doesn't seem to work out for me. Is there a graphical implementation of opencv such as roborealm available for free? Thanks,

2014-11-05 10:25:20 -0500 asked a question Finding coordinates of face in Python[Updated]

I am trying to send the coordinates of a face found with opencv over serial. I got the serial part downpath but I can't figure out how to find the coordinates of the face. I would like to if possible use the example as the base... Any ideas? Thanks ahead of time! Here is the code:

#!/usr/bin/env python

import numpy as np
import cv2

# local modules
from video import create_capture
from common import clock, draw_str

help_message = '''
USAGE: [--cascade <cascade_fn>] [--nested-cascade <cascade_fn>] [<video_source>]

def detect(img, cascade):
    rects = cascade.detectMultiScale(img, scaleFactor=1.3, minNeighbors=4, minSize=(30, 30), flags = cv2.CASCADE_SCALE_IMAGE)
    if len(rects) == 0:
        return []
    rects[:,2:] += rects[:,:2]
    return rects

def draw_rects(img, rects, color):
    for x1, y1, x2, y2 in rects:
        cv2.rectangle(img, (x1, y1), (x2, y2), color, 2)

if __name__ == '__main__':
    import sys, getopt
    print help_message

    args, video_src = getopt.getopt(sys.argv[1:], '', ['cascade=', 'nested-cascade='])
        video_src = video_src[0]
        video_src = 0
    args = dict(args)
    cascade_fn = args.get('--cascade', "../../data/haarcascades/haarcascade_frontalface_alt.xml")
    nested_fn  = args.get('--nested-cascade', "../../data/haarcascades/haarcascade_eye.xml")

    cascade = cv2.CascadeClassifier(cascade_fn)
    nested = cv2.CascadeClassifier(nested_fn)

    cam = create_capture(video_src, fallback='synth:bg=../cpp/lena.jpg:noise=0.05')

    while True:
        ret, img =
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        gray = cv2.equalizeHist(gray)

        t = clock()
        rects = detect(gray, cascade)
        vis = img.copy()
        draw_rects(vis, rects, (0, 255, 0))
        for x1, y1, x2, y2 in rects:
            roi = gray[y1:y2, x1:x2]
            vis_roi = vis[y1:y2, x1:x2]
            subrects = detect(roi.copy(), nested)
            draw_rects(vis_roi, subrects, (255, 0, 0))
        dt = clock() - t

        draw_str(vis, (20, 20), 'time: %.1f ms' % (dt*1000))
        cv2.imshow('facedetect', vis)

        if 0xFF & cv2.waitKey(5) == 27:

Sorry about the formatting... Thanks for all the help so far!

2014-06-15 15:04:50 -0500 received badge  Supporter (source)
2014-06-13 11:15:34 -0500 received badge  Editor (source)
2014-06-13 11:14:58 -0500 asked a question Finding the centroid of a blob in Python

I am a newbie to Python and OpenCV and I am trying to find the centroid of a blob. I have succesfully been able to find the blob using this code:

import cv2 import numpy as np

cap = cv2.VideoCapture(0)


# Take each frame
_, frame =

# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

# define range of blue color in HSV
lower_blue = np.array([110,50,50])
upper_blue = np.array([130,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)

k = cv2.waitKey(5) & 0xFF
if k == 27:

but I can't figure out how to find the centroid of the blob. I have looked at the Moments() command but I don't know how and where to implement it into my program.I am using Python 2.7 with the latest OpenCV package and Ubuntu 14.04 LTS. All help is appreciated and I will gladly provide detials if needed. Thanks, L

Thanks for the help so far. But is it possible that someone could provide me with some code that implements the moments() function in python. All the code I have tried so far will not run because of various errors... Thanks, L