Re: wxwidgets + opencv

807 views
Skip to first unread message

Larry

unread,
May 1, 2006, 3:06:27 AM5/1/06
to wx-u...@lists.wxwidgets.org

Hi Frank,

Yes, I did integration opencv/wxwidgets in a fairly complex project.
What exactly are u interested in ? GUI integration ? image conversion ?
camera view integration? Let me know and i will show u what I did.

Larry

give u some samples.

"Franco Amato" wrote:
> Hi people.
> Does someone have experience programming with OpenCV library and wxWidgets
> together?
> If yes can I have an example to integrate OpenCV in a wxWidgets frame?
> Best Regards
> Frank
>
> ------=_Part_15773_1120962.1146065715751
> Content-Type: text/html; charset=ISO-8859-1
> Content-Transfer-Encoding: quoted-printable
> X-Google-AttachSize: 211
>
> Hi people.<br>Does someone have experience programming with OpenCV library and wxWidgets together?<br>If yes can I have an example to integrate OpenCV in a wxWidgets frame?<br>Best Regards<br>Frank<br><br>
>
> ------=_Part_15773_1120962.1146065715751--


Kristian Nørgaard

unread,
May 1, 2006, 4:15:22 AM5/1/06
to wx-u...@lists.wxwidgets.org
Hi Larry

>Yes, I did integration opencv/wxwidgets in a fairly complex project.
>What exactly are u interested in ? GUI integration ? image conversion ?
>camera view integration? Let me know and i will show u what I did.
>
>

Oh, I am very interested too!
Was your project tested on both windows and linux?

I would very much like some sample that shows how you integrated the
output from a videocam into a wx frame.
Were you able to show both the pure camera output stream and some
manipulated videostream?

When was this done, what version of openCV? I have looked a bit on
OpenCV, but I was a bit worried about their Linux support, it seemed
like the development had focused mostly on windows. Also I got the
impression that the development in general was very slow, and I was
afraid of digging in to a dying a project...

What was/is your opinion on openCV? Did you try alternatives?

regards,
Kristian ( debian user )

Franco Amato

unread,
May 1, 2006, 10:53:53 AM5/1/06
to wx-u...@lists.wxwidgets.org
Thank you very much for your reply.
So I have to make a program that read from a camera (or file), perform operation over every frame and display image in a wxwidgets control, but I'm not able to create that control and display in the image.
Thank in advance.
Frank.
p.s. sorry for my bad english

1 May 2006 00:06:27 -0700, Larry <i...@larryo.org>:
---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-u...@lists.wxwidgets.org
For additional commands, e-mail: wx-use...@lists.wxwidgets.org


Franco Amato

unread,
May 1, 2006, 10:55:04 AM5/1/06
to wx-u...@lists.wxwidgets.org
I'm intersted in
GUI integration, image conversion and camera view integration.
Is too much?
Thanx
Frank

1 May 2006 00:06:27 -0700, Larry < i...@larryo.org>:

Larry

unread,
May 1, 2006, 8:11:12 PM5/1/06
to wx-u...@lists.wxwidgets.org

Aaa, by the way Kristian, do you know any other alternatives? Until a
few months ago I constantly did research on the net for such packages
but could not find any as compact as opencv. Only bits and pieces.

I also had many headaches trying to integrate gocr (for character and
bar code recognition) in this package. However I am not very happy with
the results ... integration worked fine (after editing many thousands
of lines of code I managed to encapsulate the c code in c++ and then
get it working with opencv and wxwidgets) however it didn't gave good
results on webcam resolution :( .. and it's also too slow. So here I
am, still digging for a good implementation.

Larry


Larry

unread,
May 1, 2006, 7:55:38 PM5/1/06
to wx-u...@lists.wxwidgets.org

Hi,

My project does pretty much all that. See
http://larryo.org/work/robotics/chorg.html - sorry there not much info
there yet and pictures are a bit outdated (more then a year old).

And, yes, I did manage to compile it on linux (redhat) to ... more then
a year ago. True is I had some problems but not with the opencv
integration but the webcam drives weren't really there like they
should.

I used wxwidgets 2.4 at the time ... I recon now with 2.6 there must be
a more elegant way to handle the conversion . For camera integration in
linux you can see the link I provide bellow my approach at the time(not
100% that was the one that worked or I re-write it meanwhile). Look in
Ccamera.cpp in between defines for win32_larry and else(linux).
However I think with the new opencv version a more elegant approach can
be done. It much depends on your needs as well ... I need full control
at frame level synchronized with the rest of the threads.

Sorry for the mess in the code, I don't have other another cleaner
example at the moment - and I have plenty of other "more" grey
areas in my projects to worrie about at the moment :) Perhaps it wont
be a bad idea to create sample on how to use these together whenever I
get some time.

Generally, I am happy with opencv. True, the development it's a bit
slow but is not dead yet :).

Let me know if I can be any further help

Larry

Links:
http://larryo.org/web/work/robotics/chorg/camera.cpp
http://larryo.org/web/work/robotics/chorg/camera.h
http://larryo.org/web/work/robotics/chorg/mainframe.cpp
http://larryo.org/web/work/robotics/chorg/mainframe.h
http://larryo.org/web/work/robotics/chorg/camview.cpp
http://larryo.org/web/work/robotics/chorg/camview.h


A code extras:

******************************frame****************
In the frame you construct your cam viewer:

// build cam canvas
m_pCamView = new CCamView( panel1, wxPoint(5,15), wxSize(354, 256) );

*******************************window******************
then in CcamView (which extends wxWindow ) I do(first two methods are
just used to handle the drawing in window by wxwidgets, the third
method does the actual conversion from iplimage to bitmap) :

////////////////////////////////////////////////////////////////////
// Method: OnPaint
// Class: CCamView
// Purose: on paint event
// Input: reference to paint event
// Output: nothing
////////////////////////////////////////////////////////////////////
void CCamView::OnPaint( wxPaintEvent& event )
{
wxPaintDC dc(this);
Draw( dc );
}

////////////////////////////////////////////////////////////////////
// Method: Draw
// Class: CCamView
// Purose: camera drawing
// Input: reference to dc
// Output: nothing
////////////////////////////////////////////////////////////////////
void CCamView::Draw( wxDC& dc )
{
// check if dc available
if( !dc.Ok( ) ){ return; }

m_bDrawing = true;

dc.BeginDrawing();

int x,y,w,h;
dc.GetClippingBox( &x, &y, &w, &h );
// if there is a new image to draw
if( m_bNewImage )
{
dc.DrawBitmap( m_pBitmap, x, y );
m_bNewImage = false;
} else
{
// draw inter frame ?
}

dc.EndDrawing();
m_bDrawing = false;

return;
}

// I call this method from the camera object to do the conversion to
bitmap so I can display with wxwidgets - it might be a better way

////////////////////////////////////////////////////////////////////
// Method: DrawCam
// Class: CCamView
// Purose: convert ipl image and handle other drawings
// Input: ipl image pointer
// Output: nothing
////////////////////////////////////////////////////////////////////
void CCamView::DrawCam( IplImage* pImg )
{
if( pImg )
{
unsigned char *rawData;

CvSize roiSize;
int step = 0;
cvGetRawData( pDstImg, &rawData, &step, &roiSize );
wxImage pWxImg = wxImage( 640,480, rawData, TRUE );

m_pBitmap = wxBitmap( pWxImg.Scale(m_nWidth, m_nHeight) );

m_bNewImage = true;
m_bDrawing = false;

Refresh( FALSE );

cvReleaseImage( &pDstImg );
}
}
************************** Camera call*********************************
pFrame = cvQueryFrame( m_pCapture );
if( pFrame )
{
// if no video image
if( !m_pVideoImg )
{
cvReleaseImage( &m_pVideoImg );
m_pVideoImg = cvCreateImage( cvSize( m_nWidth, m_nHeight ), 8, 3 );
}

if( pFrame->origin == 1 )
{
//cvFlip( pFrame, m_pVideoImg, 0 );
//cvCvtColor( m_pVideoImg, m_pVideoImg, CV_BGR2RGB );
cvConvertImage( pFrame, m_pVideoImg, CV_CVTIMG_FLIP |
CV_CVTIMG_SWAP_RB );
} else
{
cvCopy( pFrame, m_pVideoImg, 0 );
}

m_pCameraView->DrawCam( m_pVideoImg );


************************* frame camera control panel
hack***************
This is a hack I did to get the camera control panel in wxwidgets -
only for windows

////////////////////////////////////////////////////////////////////
// Method: On Video Source
// Class: CMainFrame
// Purose: when video source menu option selected
// Input: reference to event
// Output: nothing
////////////////////////////////////////////////////////////////////
void CMainFrame::OnVideoSource( wxCommandEvent& event )
{
CCamView *pView = GetCameraView();

// for widnows do this
#ifdef _WINDOWS
// hack to get the windows handler
typedef struct CvCaptureCAM_VFW
{
void* vtable;
CAPDRIVERCAPS caps;
HWND capWnd;
VIDEOHDR* hdr;
DWORD fourcc;
HIC hic;
IplImage* rgb_frame;
IplImage frame;
} CvCaptureCAM_VFW;


CvCapture* ptest = pView->m_pCamera->m_pCapture;
CvCaptureCAM_VFW* p = (CvCaptureCAM_VFW*) ptest;

capDlgVideoSource( p->capWnd );
#elif _LINUX
// else ... TODO
#endif

return;
}

////////////////////////////////////////////////////////////////////
// Method: On Video Format
// Class: CMainFrame
// Purose: when video format menu option selected
// Input: reference to event
// Output: nothing
////////////////////////////////////////////////////////////////////
void CMainFrame::OnVideoFormat( wxCommandEvent& event )
{
CCamView *pView = GetCameraView();

// for widnows do this
#ifdef _WINDOWS
// hack to get the windows handler
typedef struct CvCaptureCAM_VFW
{
void* vtable;
CAPDRIVERCAPS caps;
HWND capWnd;
VIDEOHDR* hdr;
DWORD fourcc;
HIC hic;
IplImage* rgb_frame;
IplImage frame;
} CvCaptureCAM_VFW;


CvCapture* ptest = pView->m_pCamera->m_pCapture;
CvCaptureCAM_VFW* p = (CvCaptureCAM_VFW*) ptest;

capDlgVideoFormat( p->capWnd );
#elif _LINUX
// else ... TODO
#endif

return;
}


Larry

unread,
May 1, 2006, 8:18:34 PM5/1/06
to wx-u...@lists.wxwidgets.org

Kristian Nørgaard

unread,
May 2, 2006, 2:08:38 AM5/2/06
to wx-u...@lists.wxwidgets.org
Larry wrote:

>Aaa, by the way Kristian, do you know any other alternatives?
>

I haven't looked much into this but in my googling I stumbled across:

vigra:
http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/

/ Kristian

Franco Amato

unread,
May 3, 2006, 3:05:35 PM5/3/06
to wx-u...@lists.wxwidgets.org
Thanx very much for tour program..so you think it's slow?
It run under window? It's compiled with wx2.4.2? Too many questions? Sorry
Thank again.
Best Regards
Frank

 
1 May 2006 17:18:34 -0700, Larry <i...@larryo.org>:

Larry

unread,
May 3, 2006, 6:44:13 PM5/3/06
to wx-u...@lists.wxwidgets.org

Hi Frank,

Well, I meant the way the opencv team makes new releases, bug fixes,
optimizations, etc. as being a bit slow. Otherwise I am fairly happy
with opencv... as far. It's a good tool to make your way around with.
And after all it's open source so if you aren't happy with the
performance you can dig into it and do it better.

Yes, it does run under windows as primary target. I did compile it on
linux as well more then a year ago but since then I focused more to get
the functionality done and did most of the work around windows.

Yes, I used wx2.4. I only recently got the wx2.6 installed but didn't
got yet the time to compile the thing and check for any
incompatibilities. But I am sure that it will work.

Don't worry, ask and if I have the time and the answer I will gladly
help.

Larry


Franco Amato

unread,
May 4, 2006, 9:55:02 AM5/4/06
to wx-u...@lists.wxwidgets.org
Thank my friend, you are very very very gentle.
Best Regards
Frank

3 May 2006 15:44:13 -0700, Larry <i...@larryo.org>:

Franco Amato

unread,
Jun 26, 2006, 8:48:41 AM6/26/06
to wx-u...@lists.wxwidgets.org
Hi Larry.
Hi tried your code without success...is very complex and I god several crash error.
I think there are some class missed (CEye and others?)
Hi have lots of doubts I can't solve alone.
Can U help me?

for example if I select menu->videoformat I get a crash here:

        CvCapture* ptest = pView->m_pCamera->m_pCapture;

and is not the only problem...
Another thing in the file "extra code" you sent me, I don't understand a thing (and others):
This piece of code is a function?


************************** Camera call*********************************
pFrame = cvQueryFrame( m_pCapture );
  if( pFrame )
   {
       // if no video image
       if( !m_pVideoImg )
       {
         cvReleaseImage( &m_pVideoImg );
         m_pVideoImg = cvCreateImage( cvSize( m_nWidth, m_nHeight ), 8, 3 );
       }

               if( pFrame->origin == 1 )
               {
                       //cvFlip( pFrame, m_pVideoImg, 0 );
                       //cvCvtColor( m_pVideoImg, m_pVideoImg, CV_BGR2RGB );
                       cvConvertImage( pFrame, m_pVideoImg, CV_CVTIMG_FLIP | CV_CVTIMG_SWAP_RB );
               } else
               {
                       cvCopy( pFrame, m_pVideoImg, 0 );
               }

m_pCameraView->DrawCam( m_pVideoImg );


Where must I use it?

Regards
Frank



3 May 2006 15:44:13 -0700, Larry <i...@larryo.org>:

Simon

unread,
Jun 23, 2016, 3:24:12 PM6/23/16
to wx-users, wx-u...@lists.wxwidgets.org, i...@larryo.org
Hi Larry,

I used your code and I am trying to build it, but I am getting a lot of errors, one of them being:

'CImage' does not name a type

I am not sure what I am doing wrong, I have just taken your code and added to a wxWidgetProject(version 3.0.2) on CodeBlocks(version 13.12) (on windows, opencv version 2.4.9) arbitrarily. I am a newbee on both WxWidgets and OpenCV, and the code seems highly complex. I am going through various tutorials and docs, could you please help me in the meanwhile?

Please let me know if you require more details.

Regards,
Simon
Reply all
Reply to author
Forward
0 new messages