Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cvDecodeImage - after streaming fails

Camera capture --> Encode -> stream (unsigned char )

-> Recieve -> Decode

Encoding side

unsigned char Buffer[1024*20]; IplImage *image =cvQueryFrame(capture);

const static int encodeparams[]={CV_IMWRITE_JPEG_QUALITY,60};

encode =cvEncodeImage(".jpg",image,encodeparams);

memcpy(&buffer,encode->data.ptr,sizeof(unsigned char )encode->rowsencode->cols);

decoding side

// ofcourse i am getting all the header info from encoder cols, rows // i cross verified the header info there is no error. memcpy(&Buffer,datastream,encode->rows*encode->cols); // buffer is of unsigned char decode =cvCreateMat(iRows,iCols,CV_8UC1);

decode->data.ptr=&Buffer[0];

frame = cvDecodeImage(decode,CV_LOAD_IMAGE_COLOR);
 if(!frame)
     printf(" I am not getting valid frame ");
click to hide/show revision 2
No.2 Revision

updated 2014-03-20 03:57:21 -0600

berak gravatar image

cvDecodeImage - after streaming fails

Camera capture --> Encode -> stream (unsigned char )

-> Recieve -> Decode

Encoding side

unsigned char Buffer[1024*20];
IplImage *image =cvQueryFrame(capture);

=cvQueryFrame(capture);

const static int encodeparams[]={CV_IMWRITE_JPEG_QUALITY,60};

encodeparams[]={CV_IMWRITE_JPEG_QUALITY,60}; encode =cvEncodeImage(".jpg",image,encodeparams);

encode =cvEncodeImage(".jpg",image,encodeparams);

memcpy(&buffer,encode->data.ptr,sizeof(unsigned char )encode->rowsencode->cols);

)*encode->rows*encode->cols);

decoding side

// ofcourse i am getting all the header info from encoder cols, rows
// i cross verified the header info there is no error.
  memcpy(&Buffer,datastream,encode->rows*encode->cols); 
 // buffer is of unsigned char 
  decode =cvCreateMat(iRows,iCols,CV_8UC1);

=cvCreateMat(iRows,iCols,CV_8UC1); decode->data.ptr=&Buffer[0];

decode->data.ptr=&Buffer[0];

 frame = cvDecodeImage(decode,CV_LOAD_IMAGE_COLOR);
  if(!frame)
      printf(" I am not getting valid frame ");

cvDecodeImage - after streaming fails

Camera capture --> Encode -> stream (unsigned char )

-> Recieve -> Decode

Encoding side

unsigned char Buffer[1024*20];
IplImage *image =cvQueryFrame(capture);

const static int encodeparams[]={CV_IMWRITE_JPEG_QUALITY,60};

encode =cvEncodeImage(".jpg",image,encodeparams);

memcpy(&buffer,encode->data.ptr,sizeof(unsigned char )*encode->rows*encode->cols);
  image=cvQueryFrame(Capture); 
   encode=cvEncodeImage(".jpg",image,encodeparams);

    decode=cvCreateMat(encode->rows,encode->cols,CV_8UC1);

decode->data.ptr=encode->data.ptr;

  cvShowImage("Server",image);
   cvWaitKey(1);
    Frame->iSync=0x1;
    Frame->iLength=(16+(encode->rows*encode->cols));
    Frame->iSize=(encode->rows*encode->cols);
    Frame->iWidth=(encode->rows);
    Frame->iHeight=(encode->cols);
        Frame->iSync=0x1;
    Frame->iLength=(16+(encode->rows*encode->cols));
    Frame->iSize=(encode->rows*encode->cols);
    Frame->iWidth=(encode->rows);
    Frame->iHeight=(encode->cols);

    memcpy(&bImageData[0],&Frame->iSync,sizeof(int));
    memcpy(&bImageData[4],&Frame->iLength,sizeof(int));

    memcpy(&bImageData[8],&Frame->iSize,sizeof(int));

    memcpy(&bImageData[12],&Frame->iWidth,sizeof(int));

    memcpy(&bImageData[16],&Frame->iHeight,sizeof(int));


memcpy(&bImageData[20],encode->data.ptr,sizeof(unsigned char)*encode->rows*encode->cols);

// printf("%d",length );
length = Frame->iLength;

    while( count < length)
{
        offset=send(connect,&bImageData[count],(length-count),0);

            if(offset > 1)
            {
                    count +=offset;
                  //  printf("\n Count &  %d %d \n",offset,count); 
            }
            if(offset == (-1))
            {
                printf("closed connection");
                goto _error_video_client; 
            }           
}
    recv(connect,RecvBuff,sizeof(RecvBuff),0); 

}

decoding side

define MAKEDWORD(B0,B1,B2,B3) (((unsigned long)B0)+

(((unsigned long)B1)<<8)+ (((unsigned long)B2)<<16)+ (((unsigned long)B3)<<24))

if(offset)
{
      if(size > PACKET_HEADER_SIZE )
      {   // ofcourse i am getting all using QT so this... to get the header info from encoder cols, rows
info.
          iSync   = MAKEDWORD(CopyData.at(0),CopyData.at(1),CopyData.at(2),CopyData.at(3));
          iLength = MAKEDWORD(CopyData.at(4),CopyData.at(5),CopyData.at(6),CopyData.at(7));
          iSize   = MAKEDWORD(CopyData.at(8),CopyData.at(9),CopyData.at(10),CopyData.at(11));
          iRows  = MAKEDWORD(CopyData.at(12),CopyData.at(13),CopyData.at(14),CopyData.at(15));
          iCols =  MAKEDWORD(CopyData.at(16),CopyData.at(17),CopyData.at(18),CopyData.at(19));
          std::cout << "iLength " << iLength;
          std::cout << "isize " << iSize << "iWidth " << iRows  << " iHeight" << iCols;
          offset=0;
          if((iLength < 0) && iLength > FRAME_LENGTH )
                  offset=1;
          count=size;
          memcpy(&FrameBuffer[0],&CopyData,size);
          std::cout << "Size" << size;
       }


}
else
{   std::cout << "count " << count;
    memcpy(&FrameBuffer[count],&CopyData,size); // i cross verified keep until u reach the header info there is no error.
  memcpy(&Buffer,datastream,encode->rows*encode->cols); 
 // buffer is of unsigned char 
count == length 

    count+=size;
    if(count == iLength)
    {
         std::cout << "count== length   " << iRows <<"   "<< iCols;
         std::cout << "Completed";
         decode =cvCreateMat(iRows,iCols,CV_8UC1);

   decode->data.ptr=&Buffer[0];

=cvCreateMat(iRows,iSize,CV_8UC1);
         decode->data.ptr=&FrameBuffer[20];
         frame = cvDecodeImage(decode,CV_LOAD_IMAGE_COLOR);
     if(!frame)
         printf("    if(frame)
           std::cout << "Valid Frame";
      else
       std::cout << "Not a Valid Frame "; // I am not getting valid aware why this is going invalid frame ");
after sending all the trasnmission are using unsigned char buffer.

    }
}

cvDecodeImage - after streaming fails

Camera capture --> Encode -> stream (unsigned char )

-> Recieve -> Decode

Encoding side

unsigned char Buffer[1024*20];
IplImage *image   image=cvQueryFrame(Capture); 
   encode=cvEncodeImage(".jpg",image,encodeparams);

    decode=cvCreateMat(encode->rows,encode->cols,CV_8UC1);

decode->data.ptr=encode->data.ptr;

  cvShowImage("Server",image);
   cvWaitKey(1);
    Frame->iSync=0x1;
    Frame->iLength=(16+(encode->rows*encode->cols));
    Frame->iSize=(encode->rows*encode->cols);
    Frame->iWidth=(encode->rows);
    Frame->iHeight=(encode->cols);
        Frame->iSync=0x1;
    Frame->iLength=(16+(encode->rows*encode->cols));
    Frame->iSize=(encode->rows*encode->cols);
    Frame->iWidth=(encode->rows);
    Frame->iHeight=(encode->cols);

    memcpy(&bImageData[0],&Frame->iSync,sizeof(int));
    memcpy(&bImageData[4],&Frame->iLength,sizeof(int));

    memcpy(&bImageData[8],&Frame->iSize,sizeof(int));

    memcpy(&bImageData[12],&Frame->iWidth,sizeof(int));

    memcpy(&bImageData[16],&Frame->iHeight,sizeof(int));


memcpy(&bImageData[20],encode->data.ptr,sizeof(unsigned char)*encode->rows*encode->cols);

// printf("%d",length );
length = Frame->iLength;

    while( count < length)
{
        offset=send(connect,&bImageData[count],(length-count),0);

            if(offset > 1)
            {
                    count +=offset;
                  //  printf("\n Count &  %d %d \n",offset,count); 
            }
            if(offset == (-1))
            {
                printf("closed connection");
                goto _error_video_client; 
            }           
}
    recv(connect,RecvBuff,sizeof(RecvBuff),0); 

}

decoding side

define MAKEDWORD(B0,B1,B2,B3) (((unsigned long)B0)+

(((unsigned long)B1)<<8)+ (((unsigned long)B2)<<16)+ (((unsigned long)B3)<<24))

if(offset)
{
      if(size > PACKET_HEADER_SIZE )
      {   // using QT so this... to get the header info.
          iSync   = MAKEDWORD(CopyData.at(0),CopyData.at(1),CopyData.at(2),CopyData.at(3));
          iLength = MAKEDWORD(CopyData.at(4),CopyData.at(5),CopyData.at(6),CopyData.at(7));
          iSize   = MAKEDWORD(CopyData.at(8),CopyData.at(9),CopyData.at(10),CopyData.at(11));
          iRows  = MAKEDWORD(CopyData.at(12),CopyData.at(13),CopyData.at(14),CopyData.at(15));
          iCols =  MAKEDWORD(CopyData.at(16),CopyData.at(17),CopyData.at(18),CopyData.at(19));
          std::cout << "iLength " << iLength;
          std::cout << "isize " << iSize << "iWidth " << iRows  << " iHeight" << iCols;
          offset=0;
          if((iLength < 0) && iLength > FRAME_LENGTH )
                  offset=1;
          count=size;
          memcpy(&FrameBuffer[0],&CopyData,size);
          std::cout << "Size" << size;
       }


}
else
{   std::cout << "count " << count;
     memcpy(&FrameBuffer[count],&CopyData,size); // keep until u reach the count == length 

    count+=size;
    if(count == iLength)
    {
         std::cout << "count== length   " << iRows <<"   "<< iCols;
         std::cout << "Completed";
         decode =cvCreateMat(iRows,iSize,CV_8UC1);
         decode->data.ptr=&FrameBuffer[20];
         frame = cvDecodeImage(decode,CV_LOAD_IMAGE_COLOR);
        if(frame)
           std::cout << "Valid Frame";
      else
       std::cout << "Not a Valid Frame "; // I am not aware why this is going invalid frame after sending all the trasnmission are using unsigned char buffer.

    }
}