0
import cv2.cv as cv 
import numpy as np

Capture = cv.CaptureFromCAM(0)
image = cv.QueryFrame(Capture) #here you have an IplImage
imgarray = np.asarray(image[:,:]) #this is the way I use to convert it to numpy ar

I am using this code to capture image from webcam and i want to show it on canvas,please help.the above code just activates the web cam without any error ,please can you either help may save the IplImage on hard-disk or display it on canvas.Really urgent.This is a part of the project i am doing. Help will be appreciated

I used this code using pygame

import pygame
import pygame.camera
from pygame.locals import *
import pygame.image

pygame.init()
pygame.camera.init()

camlist = pygame.camera.list_cameras()
cam = pygame.camera.Camera(camlist[0],(640,480))

if camlist:
    cam = pygame.camera.Camera(camlist[0],(640,480))
cam.start()
image = cam.get_image()

I used this code to capture image from web cam and do the same but,it does not do anything please help me either store the image on hard-disk or display it on canvas

1
  • please avoid the old cv (or cv2.cv) module. it won't be there anmore in near future. Commented Aug 18, 2014 at 8:53

1 Answer 1

2
import cv2
cam = cv2.VideoCapture(0)
winName = "image"
cv2.namedWindow(winName, cv2.CV_WINDOW_AUTOSIZE)
s, im = cam.read() # captures image
cv2.imshow(winName, im) # displays captured image
cv2.imwrite("test.bmp",im) # writes image test.bmp to disk
cv2.waitKey()
Sign up to request clarification or add additional context in comments.

2 Comments

thanks of great help ,just one more thing can i use more such images and display it on tkinter widget.otherwise thanks brother
I don't know about Tkinter much.. but once you save the captured then it'll be just like any other image so you can display it on tkinter widget

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.