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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:23:24+00:00 2026-05-24T09:23:24+00:00

I want to write data directly into the imageData array of an IplImage, but

  • 0

I want to write data directly into the imageData array of an IplImage, but I can’t find a lot of information on how it’s formatted. One thing that’s particularly troubling me is that, despite creating an image with three channels, there are four bytes to each pixel.

The function I’m using to create the image is:

IplImage *frame = cvCreateImage(cvSize(1, 1), IPL_DEPTH_8U, 3);

By all indications, this should create a three channel RGB image, but that doesn’t seem to be the case.

How would I, for example, write a single red pixel to that image?

Thanks for any help, it’s get me stumped.

  • 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-24T09:23:26+00:00Added an answer on May 24, 2026 at 9:23 am

    If you are looking at frame->imageSize keep in mind that it is frame->height * frame->widthStep, not frame->height * frame->width.

    BGR is the native format of OpenCV, not RGB.

    Also, if you’re just getting started, you should consider using the C++ interface (where Mat replaces IplImage) since that is the future direction and it’s a lot easier to work with.

    Here’s some sample code that accesses pixel data directly:

    int main (int argc, const char * argv[]) {
    
        IplImage *frame = cvCreateImage(cvSize(41, 41), IPL_DEPTH_8U, 3);
    
        for( int y=0; y<frame->height; y++ ) { 
            uchar* ptr = (uchar*) ( frame->imageData + y * frame->widthStep ); 
            for( int x=0; x<frame->width; x++ ) { 
                ptr[3*x+2] = 255; //Set red to max (BGR format)
            }
        }
    
        cvNamedWindow("window", CV_WINDOW_AUTOSIZE);
        cvShowImage("window", frame);
        cvWaitKey(0);
        cvReleaseImage(&frame);
        cvDestroyWindow("window");
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want simultaneously read and write data into file. Can i use StreamReader and
I want to write data into the file in binary form. I was trying
I am using ofstream() to write data into file, i want the program to
I want to write the bulk of data into xml file ,the data coming
I want to read weather data from Weather Unground into Matlab directly. For a
I want to write data to an output file and save it on a
Let's say there are two python scripts that want to write data to the
I want to write JSON data to a text file using jQuery and PHP.
I want to use iText to write data to pdf. Assembles that I've added
I want to write a small bit of data from my app to the

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.