Capturing an image as an array using Python OpenCV

I saw from an example how to display an image from a webcam, but how to get an image captured as an array?

import cv

capture = cv.CaptureFromCAM(0)
img = cv.QueryFrame(capture)

img.tostring () gives me weird characters. Thanks in adv.

+3
source share
4 answers

I think this is what you are looking for:

img=cv.LoadImage("asd.png")
mat=cv.GetMat(img)
mat[3,1]
(83.0, 88.0, 89.0)

in any case, you should check the opencv python cookbook for use with the PIL and NUMPY packages.

+3
source

Be sure to get opencv with numpy support. The sequence that works for me is IPL capture, conversion to cvMat, conversion to numpy:

import cv, numpy, pylab
capture = cv.CaptureFromCAM(0)
img = cv.QueryFrame(capture)
mat=cv.GetMat(img)
a = numpy.asarray(mat)
pylab.imshow(a)

, , pylab. opencv

+2

, , / .

, , - linux python.

+1
0

Source: https://habr.com/ru/post/1760689/


All Articles