Ask Your Question
0

c++ windows forms /CLR

asked 2016-01-20 11:37:34 -0600

DMMM gravatar image

Hello,

are opencv31 or previous versions just for native c++ or can we use it with windows froms? I just get errors of all kind and I don't know the reason(s). I wrote several programs with c++ - console and all are running correctly in x32 or x64 but impossible to do anything with it in windows forms.

I have changed all possible setting in visual studio but it is definitely impossible to compile a simple form when just having any openCV *.h include.

Thank you very much for your help guys!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
5

answered 2016-01-20 16:02:13 -0600

Guyygarty gravatar image

Hi,

I use OpenCV (2.4.x and 3.0.x) with windows forms (visual studio 2008, 2013, /clr compiler flag) routinely - I use OpenCV commands in form callbacks without any particular problem, probably because I cheat and declare all cv::Mats either globally in the .cpp file or locally within a function and not as part of the form so that they are technically not "managed". (in fact my form header does not even #include opencv).

It gets a bit tricky when you want opencv windows (imShow) and your form to actually interact (e.g. have setMouseCallback or createTrackBar call a form function) - the solution to that is here - but otherwise it works fine.

If you share the errors you get I may be able to help you more.

guy

edit flag offensive delete link more

Comments

I have the same challenge as written above, whenever I include a opencv .h file the program gets a Debug Assertion Failed error before any code is executed. I've done everything I know about the settings and stuff in Visual Studio to make it work, but no luck. How did you manage to work around this, how did you not include the .h files and still made it work?

Using OpenCV 3.1 and Visual Studio 2015 How did you manage to work a

troppsi gravatar imagetroppsi ( 2016-04-29 06:07:13 -0600 )edit

I add the opencv .h files in the .cpp file for the form and not in the header. I try to not have any code at all (other than the form constructor and destructor) in the header.

Guyygarty gravatar imageGuyygarty ( 2016-05-12 12:19:16 -0600 )edit

i'm sorry, but can you show me how you do it ? because i really cam't do it, please help me. i just want to build opencv and VS for my thesis :(

Rezki Oksaputri gravatar imageRezki Oksaputri ( 2017-11-24 04:26:29 -0600 )edit

see here

Guyygarty gravatar imageGuyygarty ( 2017-12-27 08:37:01 -0600 )edit

@Guygarty, thank you very much!!! It works!!!

DMMM gravatar imageDMMM ( 2017-12-29 02:08:39 -0600 )edit

great work!

jsxyhelu gravatar imagejsxyhelu ( 2018-08-19 21:35:07 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-20 11:37:34 -0600

Seen: 1,876 times

Last updated: Jan 20 '16