Ask Your Question

Klee's profile - activity

2020-10-09 21:07:16 -0500 received badge  Famous Question (source)
2018-12-14 04:21:02 -0500 received badge  Notable Question (source)
2018-05-21 01:20:08 -0500 received badge  Popular Question (source)
2016-03-30 02:29:49 -0500 answered a question Delay when grabbing frames from webcam

Thank you. I think I will not be able to read images continuously, because in my real application, my python code is doing lots of other stuff and there is no sleep time between two images. But I will always read in 5 or 10 images and throw away all but the last.

2016-03-26 09:46:27 -0500 asked a question Delay when grabbing frames from webcam

I want to use an external trigger to take a single photo from a webcam. However, my webcam behave differently than I expected. I placed the webcam in front of a digital clock and took photos every 2 minutes and then saved the photo as .jpg with the filename containing the current timestamp. The time on the first photo is the same as the first timestamp. Then the next four photos also show the clock showing the same time as the first timestamp (although they were taken at 2 min, 4 min, 6 min and 8 min). The clock on the 6th photo shows the time of the second timestamp (clock shows 2 min whereas jpg was saved at 10 min), the 7th photo shows the time of the 3rd timestamp and so on.

Timestamp jpg     Clock in the photo
00:00                   00:00
00:02                   00:00
00:04                   00:00
00:06                   00:00
00:08                   00:00
00:10                   00:02
00:12                   00:04
00:14                   00:06
00:16                   00:08

I have tried 2 webcams, 2 operating systems, and different time intervalls between 10 seconds and 2 minutes. I have tried the opencv function "read" as well as "grab" and "retrieve" and see no difference.

Code:

import cv2
import time
cap = cv2.VideoCapture(0)
steps = [120,120,120,10,10,10,60,60,10,10,10,10,10,10,0]
for n in range(len(steps)):
    t = time.strftime("%Y-%m-%d_%H-%M-%S")
    #ret, frame = cap.read()
    ret = cap.grab()
    ret,frame = cap.retrieve()
    cv2.imwrite('test_' + t + '.jpg',frame)
    time.sleep(steps[n])
cap.release()

Is this the normal expected behaviour of a webcam or is something broken here? Am I using the right functions for my purpose?

Thank you for your help!

2015-01-04 11:28:21 -0500 asked a question Why does imshow of single channel not work? data types?

Hello,

I noticed that some opencv functions work on a full image (BGR) or on a grayscale image, but not on a single colour channel. To me, the data type of single channel and a grayscale image seem to be the same. Why is it, that opencv gives error messages? Is there something different with the data type (error message "Unrecognized or unsupported array type in function cvGetMat")? What do I have to do to make it work?

Minimal Example code

import cv2
import cv

cap = cv2.VideoCapture(0)
ret, raw = cap.read()
cap.release()
print(raw.dtype) # uint8
cv.imshow('raw',raw)

# works also for grayscale
grayscale = cv2.cvtColor(raw,cv.CV_BGR2GRAY)
print(grayscale.dtype) # uint8
print(grayscale.size) # 76800
cv2.imshow('grayscale',grayscale)

# does not work for single channel
red = raw[...,2]
print(red.dtype)
print(red.size)
cv2.imshow('red',red)
2014-07-18 06:07:07 -0500 received badge  Editor (source)
2014-07-18 06:04:10 -0500 asked a question read display numbers - distortion and rotation?

I want to read the numbers on a display using a web cam. The picture might be distorted and rotated (it would make my setup much easier if I could allow for arbitrary rotation of the display with respect to the camera). I can put some coloured marks next to the display for orientation.

My idea is, that it must be quite simple to find the red dots at the two top coners of my display and the two yellow dots at the bottom corners of my display and then distort the picture so that I get a nice rectangle.

I guess, opencv offers the right functions to do this, so that I do not have to program it from scratch. But I am new to opencv. Can anyone, who knows opencv a bit better givve me some hints what functions to look at? Is there a function that distorts my picture when the coordinates of four pixels are given?

Or am I completely on the wrong track and is there a better way to read numbers from a lcd display?

Thank you in advance!