1. 程式人生 > >opencv mat互轉byte

opencv mat互轉byte

byte * matToBytes(Mat image)
{
   int size = image.total() * image.elemSize();
   byte * bytes = new byte[size];  // you will have to delete[] that later
   std::memcpy(bytes,image.data,size * sizeof(byte));
}




Mat bytesToMat(byte * bytes,int width,int height)
{
    Mat image = Mat(height,width,CV_8UC3,bytes).clone(); // make a copy
    return image;
}