dom96 / nim-opencv

Nim OpenCV wrapper
MIT License
55 stars 7 forks source link

Collecting raw byte data of image/frame into Nim's array/sequence. #11

Closed eagledot closed 4 years ago

eagledot commented 4 years ago

Code provided in opencv/tests/camera.nim works fine but i have not found a way to get the image/frame data into a nim's sequence/array. It is my understanding that default arguments are width:640 ,height:480 , channels:3 resulting in 921600 bytes of data .But the length of data is not constant and is generally less than 921600 bytes.

According to the code openCV returns a pointer to the string data i.e of type cstring.

Extra code i used to access the raw data is like this:

  . . . . . .
  . . . . . . 
 var frame = queryFrame(capture)
 var imgData =  cast[seq[uint8]](toSeq($frame.imageData))
 echo("len of imgData: ",imgData.len)

Shouldn't the data length be equal to 921600 for each frame??.

eagledot commented 4 years ago

I was my mistake to first cast frame.imageData to string using $.

It works simply as:

 var imgData = cast[array[921600,uint8]](frame.imageData)