Ask Your Question

Adam Pash's profile - activity

2013-12-15 11:47:04 -0600 received badge  Editor (source)
2013-12-15 11:45:03 -0600 asked a question Converting pixel data from JavaScript to OpenCV's Mat

I'm trying to use an OpenCV port in Google Chrome's Native Client, and things seem to be working okay, but I'm trying to hand off an image from a canvas element in JavaScript to OpenCV (in C++).

From JavaScript, I'm passing my C++ module a pixel array that's a Uint8ClampedArray (you get this in JavaScript by calling context.getImageData(args)), and I can send that as a buffer to my OpenCV module.

I'd like to convert this buffer array to an OpenCV Mat type.

Currently the image data looks like this:

pp::VarArrayBuffer array_buffer(dictionary.Get("data"));

(The dictionary is just a JSON object passed to OpenCV, where "data" contains the array buffer.)

And I've cast that to uint32_t

uint32_t* pixels = static_cast<uint32_t*>(array_buffer.Map());

But what I really need to do is figure out a way to translate that pixel array data into OpenCV's Mat type for processing. Any suggestions? (Thanks so much for any suggestions!)

**Btw, this is what NativeClient's pp::VarArrayBuffer is all about.