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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:17:43+00:00 2026-06-17T18:17:43+00:00

I need to convert image, that was loaded with CImg library into format of

  • 0

I need to convert image, that was loaded with CImg library into format of image, which can be used in OpenCV.

The problem is that CImg creates uchar array, where data stored in the following way (in the case of 3-channel image):

  1. first there are pixels of Red Channel,
  2. then all pixels of Green channel follows,
  3. then – Blue channel.

It looks like this: R R R R R R …. G G G G G G … B B B B B B…

OpenCV stores data in a differnt way: B G R B G R B G R B G R…

Here is my code where I convert from CImg to IplImage:

CImg<uint8_t> src;
src.load_jpeg_buffer(srcData, size);
size_t width = src._width;
size_t height = src._height;
size_t nChannels = src._spectrum;
size_t depth = 8;

IplImage* m_image = cvCreateImage(cvSize(width, height), depth, nChannels); 
for(size_t i = 0; i < height; i++)
{
    for(size_t j = 0; j < width;j++)
    {
        for(size_t k = 0; k < nChannels; k++)
        { 
            ((m_image->imageData + i * m_image->widthStep))[j * nChannels + nChannels - 1 - k] =
                    src._data[k * src.size() / 3 + k + (i * m_image->widthStep + j * nChannels) / 3];   
        }
    }
}

This code worked fine. Converted image of OpenCV format was the full copy of the original image.

I tested this code with valgrind. It said that it causes a lot of memory problems. I can’t find the cause of this memory problems.

I will be grateful, if you have any ideas on this matter!
Or may be you know another method, which can load image from buffer in OpenCV (not cvDecodeImage).

  • 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-17T18:17:45+00:00Added an answer on June 17, 2026 at 6:17 pm

    The problems weren’t in my code. As I found out OpenCV library functions cause memory problems. Examples of messages of valgrind are:

    Use of uninitialised value of size 8
    ==16460==    at 0x6500539: void cv::CvtColorLoop<cv::RGB2Gray<unsigned char> >(cv::Mat const&, cv::Mat&, cv::RGB2Gray<unsigned char> const&) (in /usr/local/lib/libopencv_imgproc.so.2.4.2) 
    
    ==16488== 151,812 bytes in 1 blocks are possibly lost in loss record 3,419 of 3,425
    ==16488==    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==16488==    by 0x56A2470: cv::fastMalloc(unsigned long) (in /usr/local/lib/libopencv_core.so.2.4.2)
    
    ==16488== LEAK SUMMARY:
    ==16488==    definitely lost: 19,988 bytes in 171 blocks
    ==16488==    indirectly lost: 15,201,012 bytes in 311 blocks
    ==16488==      possibly lost: 1,202,769 bytes in 3,618 blocks
    ==16488==    still reachable: 693,651 bytes in 3,733 blocks
    ==16488==         suppressed: 0 bytes in 0 blocks
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an transparent .PNG image that I need to convert into an .CUR
I need to convert a PNG Image loaded from a file into an 8
I have a problem in silverlight which I need to convert this image(from database
I need to convert image sequences(ie,png) to video file in iPhone. How i can
I need to convert a image to base64binary content. Can we do it in
I have a 1000x1000 300dpi image that I need to convert to a 100x100
I have a java.awt.Image that I need to add CCITT T.6 compression and convert
I have a image/bitmap (I can make it either) in c++ that I need
Hello i need to read a 2d black and white image and convert that
In C#, I need to convert an image that I have already converted to

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.