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

  • Home
  • SEARCH
  • 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 6222927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:24:01+00:00 2026-05-24T08:24:01+00:00

I tried several methods to open an image and split the channels. I just

  • 0

I tried several methods to open an image and split the channels. I just want 3 Matrix to work with. I don’t know whats wrong.
Here my code:

    IplImage* img = cvLoadImage( "C:\\foo.jpg" ); 
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE ); 
cvShowImage( "Example1", img );
std::cout << "Hight: " << img->height << " Width: " << img->width;

CvMat* imgR= cvCreateMat(img->width,img->height,CV_8UC1);
CvMat* imgG= cvCreateMat(img->width,img->height,CV_8UC1);
CvMat* imgB= cvCreateMat(img->width,img->height,CV_8UC1);

cvSplit(&img, imgB, imgG, imgR, NULL);

cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
return 0;

The problem is the line cvSplit(&img, imgB, imgG, imgR, NULL);. The program always crash and I don’t know why.

Edit1: Exception:

error -(206) Unrecognized or unsupported array type

Edit2: If i use img instead of &img I get this exception:

An error occurred.
..\..\..\..\ocv\opencv\src\cxcore\cxconvert.cpp:877: error: (-215) dvec[j].size(
) == src.size() && dvec[j].depth() == src.depth() && dvec[j].channels() == 1 &&
i < src.channels()

Solution:
I was a not aware of the differnce between cv::Mat, cvMat and IplImage.
This is the solution:

    IplImage *r = cvCreateImage(cvGetSize(img), img->depth, 1);
    IplImage *g = cvCreateImage(cvGetSize(img), img->depth, 1);
    IplImage *b = cvCreateImage(cvGetSize(img), img->depth, 1);

    cvSplit(img, b, g, r, NULL);
  • 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-24T08:24:02+00:00Added an answer on May 24, 2026 at 8:24 am

    if cvloadImage is returning a pointer to an iplImage then you don’t need the ‘&’ on img it’s already a pointer

    cvSplit takes cvMat* a iplImage* isn’t the same, you need to convert it to a cvmat
    see http://opencv.willowgarage.com/documentation/cpp/c++_cheatsheet.html

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

Sidebar

Related Questions

I've tried several things already, std::stringstream m; m.empty(); m.clear(); both of which don't work.
I tried several methods to find out what part of a html string is
I have tried several methods, but problems always exist. Sometimes the sub-window didn't refresh
I've tried several methods of keeping a log of my day-to-day activity when writing
I don't want to discuss the merits of this approach, just if it is
I've tried several methods, from Linq to loading the data to an XML document,
i have tried several methods of trying to extract values from an XML file
I'm building a much much larger program, and I've tried several methods (all of
I have tried several methods but none is playing the file2.m4v using html5 see
I tried several methods to find out what part of a html string is

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.