Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eagledot opened this issue Apr 7, 2020 · 1 comment
Closed

Comments

@eagledot
Copy link

eagledot commented Apr 7, 2020

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
Copy link
Author

eagledot commented Apr 8, 2020

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

It works simply as:

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

@eagledot eagledot closed this as completed Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant