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
我正在使用此代码从网络摄像头捕获图像,我想在画布上显示它,请帮助。上面的代码只是激活网络摄像头没有任何错误,请你帮助可以保存硬盘上的IplImage或者在画布上显示它。非常紧急。这是我正在做的项目的一部分。帮助将不胜感激
我使用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()
我使用此代码从网络摄像头捕获图像并执行相同操作,但它没有做任何事情请帮我将图像存储在硬盘上或在画布上显示
答案 0 :(得分: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()