Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9094673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:24:19+00:00 2026-06-16T23:24:19+00:00

I am trying to capture frames from a Logitech HD cam connected to a

  • 0

I am trying to capture frames from a Logitech HD cam connected to a Raspberry Pi through usb, the RP is running arch linux and I am using OpenCV C api and a TCP client.

The TCP server is running c++(QT) under ubuntu.

I am storing the frame->imageData in a buffer and then send the data in the buffer.

this is a proof of concept that I can save a frame to a buffer then reconstruct a new frame which is tmpbuffer from the buffer,actually this code is running perfectly:

CvCapture *capture = cvCaptureFromCAM(1);
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
    int i =1;

   while ( 1 ) {
     // Get one frame
     IplImage* frame = cvQueryFrame( capture );
     CvSize size;
     size.height = 480;
  size.width = 640;
     IplImage* tmpframe = cvCreateImageHeader(size, IPL_DEPTH_8U, 3); //create a new frame
     if ( !frame ) {
       //fprintf( stderr, "ERROR: frame is null...\n" );
       getchar();
       break;
     }else
     {
         //std::cout<<i<<std::endl;
         char buffer[frame->imageSize];
         snprintf(buffer,frame->imageSize,"%s",frame->imageData);
         //printf("frame->height= %s\n",buffer);

         tmpframe->imageData = buffer;
         printf("data %s\n",tmpframe->imageData);

         //snprintf(IDbuffer,10,"%d",frame->ID);
         //printf("frame->ID= %s\n",IDbuffer);
         i++;
     }
     cvShowImage( "mywindow", tmpframe );

Here is my client.c file:

#include <opencv/cv.h>
 #include <opencv/highgui.h>
 #include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>


void error(char *msg)
{
 perror(msg);
 exit(0);
}

int main(int argc,char *argv[])
{

int sockfd,portno,n;
 struct sockaddr_in serv_addr;
 struct hostent *server;


 if(argc <3)
 {
  fprintf(stderr,"usage %s hostname portname port\n",argv[0]);
  exit(0);
 }

 portno = atoi(argv[2]);
 sockfd = socket(AF_INET , SOCK_STREAM,0);

 if(sockfd < 0)
 {
  error("ERROR OPENING SOCKET");
 }

 server = gethostbyname(argv[1]);
 if(server == NULL)
 {
  fprintf(stderr,"ERROR,NO SUCH HOST\n");
  exit(0);
 }

 bzero((char*)&serv_addr,sizeof(serv_addr));
 serv_addr.sin_family = AF_INET;

 bcopy((char*)server->h_addr,(char*)&serv_addr.sin_addr.s_addr,server->h_length);
 serv_addr.sin_port = htons(portno);

 if(connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0)
 {
  error("ERROR CONNECTING");
 }
    CvCapture *capture = cvCaptureFromCAM(1);
       // Show the image captured from the camera in the window and repeat
        int i =1;

       while ( 1 ) {
         // Get one frame
         IplImage* frame = cvQueryFrame( capture );
         if ( !frame ) {
           //fprintf( stderr, "ERROR: frame is null...\n" );
           getchar();
           break;
         }else
         {
             i++;
         }

         char *msg = frame->imageData;
         char buffer[frame->imageSize];
         bzero (buffer,frame->imageSize);
         snprintf(buffer,frame->imageSize,"%s",msg);
 n=write(sockfd,buffer,frame->imageSize);
 if(n <0)
 {
  error("ERROR READING FROM SOCKET");
 }
 //printf("%s\n",buffer);


 }
return 0;
}

and this is how I am receiving data on my server:

void HostConnector::readyRead()
{
    QByteArray Data = socket->readAll();

    CvSize size;
    size.height = 480;
    size.width = 640;
    IplImage *frame = cvCreateImageHeader(size, IPL_DEPTH_8U, 3);


    frame->imageData = Data.data();
    cvShowImage( "mywindow", frame );

}

But the server is crashing !!
a segmentation fault at

cvShowImage( "mywindow", frame );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:24:20+00:00Added an answer on June 16, 2026 at 11:24 pm

    Two issues I see without real close examination of the code:

    • You are using printf(3)-style functions to format binary data. That is wrongTM. The length of the resulting string would not be the same as the length of the image, and binary data might have zero bytes in the middle, or not have zero terminator.
    • You are using temporary buffer (char buffer[frame->imageSize]) outside of its scope – that is probably the cause of the segmentation fault.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to capture frames from a Logitech HD cam connected to a
I'm trying to grab frames from a web cam using OpenCV. I also tried
I am trying to grab consecutive frames from android using opencv VideoCapture class. Actually
I am trying to detect the face from the webcam using opencv python on
I am trying to read an AVI file using openCV. After getting the capture,
I'm trying to use opencv to save frames from a webcam as jpgs or
I'm trying to process large AVI files (approx. 61000 frames, 505MB) with OpenCV, using
I trying to capture packets using SharpPcap library. I'm able to return the packets
I'm trying to capture packets from two devices on my network. I have tcpdump
I'm trying to capture audio, using the method in this question ; with AVCaptureSession

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.