Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to split r,g,b channel image from Mat data pointer #1653

Open
futureflsl opened this issue Feb 18, 2024 · 1 comment
Open

how to split r,g,b channel image from Mat data pointer #1653

futureflsl opened this issue Feb 18, 2024 · 1 comment
Labels
question Further information is requested

Comments

@futureflsl
Copy link

futureflsl commented Feb 18, 2024

I known Cv2.Split can complete this funtion,but some time,we have to use pointer convert to r,g,b channel,like this

           Mat image = Cv2.ImRead("E:\\animal.jpg");
            int out_h = image.Height;
            int out_w = image.Width;
            int channel_step = out_h * out_w;
            Mat rmat =new Mat(out_h, out_w, MatType.CV_32FC1, image.CvPtr);
            Mat gmat = new Mat(out_h, out_w, MatType.CV_32FC1, image.CvPtr+channel_step);
            Mat bmat = new Mat(out_h, out_w, MatType.CV_32FC1, image.CvPtr+2 * channel_step);

            rmat *= 255f;
            gmat *= 255f;
            bmat *= 255f;
            Cv2.ImShow("R",rmat);
            Cv2.ImShow("G", gmat);
            Cv2.ImShow("B", bmat);
            Cv2.WaitKey(0);
            Cv2.DestroyAllWindows();

but the code can not run well,how modify it to work normally?

@shimat
Copy link
Owner

shimat commented Feb 24, 2024

You should first consider using Cv2.Split(), but you may find the following page helpful for other methods:
https://stackoverflow.com/questions/21619609/split-channels-from-rgb-array-in-c-without-opencv

@shimat shimat added the question Further information is requested label Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants