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 6089309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:05:06+00:00 2026-05-23T12:05:06+00:00

I have a server in linux using the Berkeley_sockets and I create a TCP

  • 0

I have a server in linux using the Berkeley_sockets and I create a TCP connection with an iPod client. I have an IplImage* img; to send from the server to the iPod. I use the write(socket,/*DATA*/,43200); command and the data i tried to send is: reinterpret_cast<char*>(img), img and img->imageData. All of this choices actually send any kind of data.

On the iPod side I receive data this way (as i’ve seen here in SO. Don’t mind the complicated stuff, it’s just for receiving all the data from a single image.):

bytesRead = [iStream read: (char*)[buffer mutableBytes] + totalBytesRead maxLength: 43200 - totalBytesRead];

After receiving the whole image, i have this:

[buffer setLength: 43200];
NSData *imagem = [NSData dataWithBytes:buffer length:43200];
UIImage *final= [self UIImageFromIplImage:imagem];

Now.. i know i could have openCV working on the iPod, but i can’t find a simple explanation on how to get it to work, so I used the second code from this webpage and adapted it, since i know all the specifications of my image (for instance I set up all the variables from the CGImageCreate() function.):

- (UIImage *)UIImageFromIplImage:(NSData *)image {

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();

// Allocating the buffer for CGImage
NSData *data = [NSData dataWithBytes:image length:43200];

CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)data);

// Creating CGImage from chunk of IplImage    
size_t width = 240;
size_t height = 180;
size_t depth = 8;             //bitsPerComponent
size_t depthXnChannels = 8;   //bitsPerPixel
size_t widthStep = 240;       //bytesPerRow

CGImageRef imageRef = CGImageCreate(width, height, depth, depthXnChannels, widthStep, colorSpace, kCGImageAlphaNone|kCGBitmapByteOrderDefault,provider, NULL, false, kCGRenderingIntentDefault);

// Getting UIImage from CGImage
UIImage *ret = [UIImage imageWithCGImage:imageRef];
lolView.image = ret;
CGImageRelease(imageRef);
CGDataProviderRelease(provider);
CGColorSpaceRelease(colorSpace);
return ret;

}

THE PROBLEM: When I display the image, I get it completely weird and ´random´, even though the image sent is always the same. I really have no idea what’s wrong..

PS: The TCP connection is working fine with other data, like numbers or words. And the image is grayscale.

Thanks for all the help.

  • 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-05-23T12:05:07+00:00Added an answer on May 23, 2026 at 12:05 pm

    I got it working like this.
    On the server side (code::blocks in linux with openframeworks (& ofxOpenCv)):

    img.allocate(240, 180, OF_IMAGE_COLOR);                    //ofImage
    img2.allocate(240, 180);                                   //ofxCvColorImage
    frame = cvCreateImage(cvSize(240,180), IPL_DEPTH_8U, 3);   //IplImage
    bw = cvCreateImage(cvSize(240,180), IPL_DEPTH_8U, 1);      //IplImage
    gray.allocate(240, 180);                                   //ofxCvGrayscaleImage
    
    
    ///ofImage
    img.loadImage("lol.jpg");
    
    ///ofImage -> ofxCvColor
    img2.setFromPixels(img.getPixels(), 240, 180);
    
    ///ofxCvColor -> IplImage
    frame = img2.getCvImage();
    
    ///IplImage in GRAY
    cvCvtColor(frame,bw,CV_RGB2GRAY);
    cvThreshold(bw,bw,200,255,CV_THRESH_BINARY);  //It is actually a binary image
    gray = bw;
    pix = gray.getPixels();
    
    n=write(newsockfd,pix,43200);
    

    On the client side (iPod 4.3):

    -(UIImage *) dataFromIplImageToUIImage:(unsigned char *) rawData;
    {
    size_t width = 240;
    size_t height = 180;
    size_t depth = 8;                   //bitsPerComponent
    size_t depthXnChannels = 8;         //bitsPerPixel
    size_t widthStep = 240;             //bytesPerRow
    
    CGContextRef ctx = CGBitmapContextCreate(rawData, width, height, depth, widthStep,  CGColorSpaceCreateDeviceGray(), kCGImageAlphaNone);
    
    CGImageRef imageRef = CGBitmapContextCreateImage (ctx);
    UIImage* rawImage = [UIImage imageWithCGImage:imageRef];  
    
    CGContextRelease(ctx);  
    
    myImageView.image = rawImage;  
    return rawImage;
    
    free(rawData);
    }
    

    Probably there’s an easier way to do this, but hey, gets the work done. Hope this helps anyone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two machines I work on: Windows Client (Development Machine) Linux Web Server
I have a linux server (Red Hat 4) with one serial port connection to
We have a Linux server application that is comprised of a number of open-source
I have a Linux server with multiple ips (so, multiple eth0, eth0:0, eth0:1 etc).
On one Linux Server running Apache and PHP 5, we have multiple Virtual Hosts
I have a rails application running on a Linux server. I would like to
I have an app that executes commands on a Linux server via SSH just
I have a PHP script (running on a Linux server) that ouputs the names
I'm new to Linux and have inherited keeping our single linux server running. It's
I have a Linux web server farm with about 5 web servers, web traffic

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.