Converting OpenCV bitmap (Mat) to wxBitmap

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
Post Reply
PB
Part Of The Furniture
Part Of The Furniture
Posts: 2547
Joined: Sun Jan 03, 2010 5:45 pm

Converting OpenCV bitmap (Mat) to wxBitmap

Post by PB » Wed Oct 07, 2020 6:09 pm

OpenCV itself can show a bitmap using imshow() function but sometimes one may want to display a bitmap acquired with OpenCV using a wxWidgets GUI. The most convenient class for doing that in wxWidgets is wxBitmap.

The function

Code: Select all

bool ConvertMatBitmapTowxBitmap(const cv::Mat& matBitmap, wxBitmap& bitmap)
converts an OpenCV bitmap encoded as BGR CV_8UC3 (the most common format) to a wxBitmap. The function also comes with a simple program which uses OpenCV and wxWidgets to acquire and display bitmaps coming from several sources: image file, video file, default webcam, and IP camera. The program also benchmarks how long a bitmap took to acquire, convert, and display.

All the code and additional information is available here:
https://github.com/PBfordev/wxopencvtest

UI of the test app
wxopencvtest.png

Post Reply