Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Thanks berak.

I finally did encoding and decoding using mat my code below the data is streamed using tcp Let me know if anyquestions. Encoding

#define JPEG_HEADER_0     0xff
#define JPEG_HEADER_1     0xd8

#define JPEG_END_2        0xff
#define JPEG_END_1        0xd9

Mat drawing; unsigned char VideoBuffer[1024*10] ; //ofcourse keep u r req size vector<int> param = vector<int>(2);

param[0]=CV_IMWRITE_JPEG_QUALITY;

param[1]=60;//default(95) 0-100

vector<uchar> encodeBuff;//buffer for coding
        imencode(".jpg",drawing,encodeBuff,param);      
        pthread_mutex_lock(&buffer_sync);
if(PacketSize > VIDEO_BUFFER_SIZE)
            printf("ERROR Packet Size --------> %d",PacketSize );
        PacketSize=encodeBuff.size();
        memcpy(&VideoBuffer[0],(char*)&encodeBuff[0],PacketSize);

Decoding

imageptr=&SendBuffer[4]; // ok i receive in sendbuffer of unsigned char

 if(  SendBuffer[4]== JPEG_HEADER_0 && 
                  SendBuffer[5] == JPEG_HEADER_1 && 
                          SendBuffer[length+3]== JPEG_END_1 &&
              SendBuffer[length+2] ==JPEG_END_2 )                 
             {

    std::vector<uchar> decodebuff(imageptr,imageptr+(size-4));
    Mat decode =imdecode(Mat(decodebuff),CV_LOAD_IMAGE_COLOR);
   }