Ask Your Question
-2

webcam capture but don't open windows with image [closed]

asked 2017-03-06 05:06:49 -0500

Edison gravatar image

updated 2017-03-06 20:17:20 -0500

Tetragramm gravatar image

Hi.

Ubuntu 16.04, opencv 3, python 2.7.

I can see the light, close to the notebook camera, lit.

I print the pixels being captured. But the window with image doesn't show up.

My notebook Graphics are:

 sudo lshw -C video
  *-display               
       description: VGA compatible controller
       product: Haswell-ULT Integrated Graphics Controller
       vendor: Intel Corporation
       physical id: 2
       bus info: pci@0000:00:02.0
       version: 0b
       width: 64 bits
       clock: 33MHz
       capabilities: msi pm vga_controller bus_master cap_list rom
       configuration: driver=i915 latency=0
       resources: irq:43 memory:f7400000-f77fffff memory:d0000000-dfffffff ioport:f000(size=64)
  *-display
       description: 3D controller
       product: GF117M [GeForce 610M/710M/810M/820M / GT 620M/625M/630M/720M]
       vendor: NVIDIA Corporation
       physical id: 0
       bus info: pci@0000:08:00.0
       version: a1
       width: 64 bits
       clock: 33MHz
       capabilities: pm msi pciexpress bus_master cap_list rom
       configuration: driver=nvidia latency=0
       resources: irq:47 memory:f6000000-f6ffffff memory:e0000000-efffffff memory:f0000000-f1ffffff ioport:d000(size=128) memory:f7000000-f707ffff

Cheese opens a window and shows my ugly face. So, it's not the camera.

Any idea? Thanks in advance.

Edison.

I have to give the info you asked here for the site is telling me to wait 2 days to answer.

1 - my code follows:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while True:
    #capture frame by frame
    ret, img = cap.read()
#    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    cv2.imshow('test', img)


cv2.waitKey(0) & 0xFF
cv2.destroyAllWindows()
cap.release()

2 - no erros reported

3- install of python bindings according instructions from Adrian, PyIage blog, using apt-get install. (if you prefer I can post the libs installed here, specially those that refer to video.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2017-05-03 10:33:31.546052

Comments

could you add your code, please ?

do you get any errors ?

how did you install the python bindings ?

berak gravatar imageberak ( 2017-03-06 05:28:21 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-03-07 04:37:41 -0500

updated 2017-03-07 04:39:19 -0500

That code would never work. Indentation (the lines and spaces between code instructions) is key in Python, and, as you indented you code, the cv2.waitKey() instruction is out of the while loop, thus the image will not show. Change your code to:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while True:
    #capture frame by frame
    ret, img = cap.read()
#    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    cv2.imshow('test', img)
    cv2.waitKey(0) & 0xFF

cv2.destroyAllWindows()
cap.release()

Note: cv2.waitKey() is necessary so window has time to render the image, without it the image will not show. The input argument of that method is the time it should wait in milliseconds. If it is set to 0, it is waiting for you to press a key to move on to the next cycle.

edit flag offensive delete link more

Comments

Hi, fellows. Thanks for the answers. I was able to solve the problem with the first answer. My bad not to pay attention to indentation. Maybe this question can be considered CLOSED. Thanks again.

Edison gravatar imageEdison ( 2017-05-03 10:30:22 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-03-06 05:06:49 -0500

Seen: 1,950 times

Last updated: May 03 '17