# How to save a cam snapshot?

**URL:** https://forum.opencv.org/t/how-to-save-a-cam-snapshot/4481
**Category:** C++
**Tags:** core
**Created:** [July 27, 2021, 6:38am UTC](https://forum.opencv.org/t/how-to-save-a-cam-snapshot/4481 "2021-07-27T06:38:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![michael](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/michael/32/2686_2.png) [@michael](https://forum.opencv.org/u/michael)
#### Post date: [July 27, 2021, 6:38am UTC](https://forum.opencv.org/t/how-to-save-a-cam-snapshot/4481/1 "2021-07-27T06:38:34Z")

</div>

HI,  
I have an unsigned char array, where the cam driver gives me the image data:  
unsigned char\* imgBuf = new unsigned char[imgSize];  
ASIGetDataAfterExp(CamNum, imgBuf, imgSize);

ho to save this with opencv ?  
I tried  
Mat save\_img;  
imgBuf \>\> save\_img;  
if(save\_img.empty())  
{  
std::cerr \<\< “Something is wrong with the webcam, could not get frame.” \<\< std::endl;  
}bei m  
// Save the frame into a file  
imwrite(“test.jpg”, save\_img); // A JPG FILE IS BEING SAVED

but it gives me:  
main\_SDK2\_snap.cpp:255:11: error: no match for \u2018operator\>\>\u2019 (operand types are \u2018unsigned char\*\u2019 and \u2018cv::Mat\u2019)  
imgBuf \>\> save\_img;

please help !!!

---

<div class="post-metadata">

### Author: ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)
#### Post date: [July 27, 2021, 6:45am UTC](https://forum.opencv.org/t/how-to-save-a-cam-snapshot/4481/2 "2021-07-27T06:45:17Z")

</div>

there is no `>>` operator for raw pointers here,  
but, if you know width, height and type, you can setup a cv::Mat like:

```
Mat img(h, w, CV_8U); // preallocated 8bit grayscale

// and read your data directly into that
ASIGetDataAfterExp(CamNum, img.data, imgSize);

// Now save the frame into a file
imwrite(“test.jpg”, img);
```
