I am trying to adapt the following code to my needs (many thanks to PBfordev, the Author!) https://github.com/PBfordev/wxopencvtest
The code consists (very basically) in a worker thread that polls every few ms an OpenCV Videocapture instance and if data is available emits a wxEVT_CAMERA_FRAME event. The (main thread) event handler converts the openCV image in a wxBitmap, and calls the setBipmap routine of the following class, derived from wxScrolledCanvas, which in turn calls the paint handler OnPaint:
Code: Select all
class wxBitmapFromOpenCVPanel : public wxScrolledCanvas
{
public:
wxBitmapFromOpenCVPanel(wxWindow* parent);
bool SetBitmap(const wxBitmap& bitmap, const long timeGet, const long timeConvert);
private:
wxBitmap m_bitmap;
.....
virtual void OnPaint(wxPaintEvent&);
};
The original code works flawlessly. But I would like to add the possibility to zoom in and out. So I modified the OnPaint event of the original code as follows.
Code: Select all
void wxBitmapFromOpenCVPanel::OnPaint(wxPaintEvent&)
{
wxAutoBufferedPaintDC dc(this);
dc.Clear();
if ( !m_bitmap.IsOk() ); //m_bitmap is the wxBitmap instance object already converted
return;
DoPrepareDC(dc); //as far as I understood this routine should (among other things) keep track of the current scrolled position
dc.SetUserScale(ZoomFactor, ZoomFactor); //<-- FIRST MODIFICATION: ZoomFactor is a global variable set by the main Frame class
SetVirtualSize(m_bitmap.GetSize()*ZoomFactor);//<--SECOND MODIFICATION; necessary to correctly scroll the zoomed image
dc.DrawBitmap(m_bitmap, 0, 0, false);
....overlays are drawn
The problem is that when I zoom in and the image get larger than the window, the scrollbars appears (correctly) but scrolling doesn´t work. Any new frame is shown with origin in (0,0). The scrollbars don´t move (apparently, maybe that due to the high frame rate they move and get back at each new frame). So it looks as at each new frame the position of the scrollwindow is reset and the window doesn´t keep track of the scrolled position.
If instead of a series of frames from a webcam I load a static image I can scroll normally.
Now if for example I pause the camera, I can scroll the static image that remains on the screen. But wherever I scroll, as soon as I restart the camera the frame are again shown with the origin in the pixel (0,0).
I even tried to manage the scrolling in a "manual" fashion, saving the scrolled position at each scrolling event by wxScrolled::GetViewStart() and setting this saved position again in the OnPaint handler by wxScrolled::Scroll(). It resulted in a miserable failure.
I hope I could make my problem clear, and someone has some suggestion, how to solve this issue!
thank you in advance