If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
- Earned a small fee
- Posts: 14
- Joined: Mon Oct 18, 2021 1:27 pm
I have some processing algorithms done using opencv in monogray images. I was wondering what's the best way to transform the cv::Mat object to a wxBitmap object in terms of speed and type of images. I am working on the images types CV_32FC1 that after is normalized to CV16UC1. As you see they have one channel so they are in gray scale, also I am doing stuff with CV_8UC1 images.
At the moment in order to convert my cv::Mat images to wxBitmap I am doing the following:
Code: Select all
// converting cv bitmap into wxBitmap
cv::cvtColor(image, image, cv::COLOR_GRAY2BGR);
wxImage test(image.cols, image.rows, image.data, true);
m_bitmap = wxBitmap(test);
So far is working and I can see the wxbitmap display in my image panel. Is this enough or there are better ways to handle this conversion?
- Part Of The Furniture
- Posts: 3176
- Joined: Sun Jan 03, 2010 5:45 pm
I will not comment of efficiency, as I assume you are already aware about other conversion methods such ConvertMatBitmapTowxBitmap() here
. This should be trivial to benchmark.
However, I am quite surprised your code is working. Based on the second parameter of cvtColor(), I would assume the converted Mat image is stored as BGR while wxImage expects the data as RGB. Depending on the image content, the red and blue channels being swapped may not be noticeable at first glance, I would make sure the wxBitmap colors are really correct. Of course, if all the images are always only in grayscale, then it does not matter as R and B are same...