Computer vision? (C#)



  • Anybody have a (good) site that explains how to get started with computer vision? I'm c# competent, but not much experience with anything related to ui/graphics programming.

    Text tutorials with screenshots preferred, YouTube videos tend to have about 2 minutes of useable tutorials in a 30 minute video.

    I'd prefer not jumping in to a full on code project )the website) since they don't typically explain why they made the decisions they did, and often have huge issues.

    To start I'd like to be able to start with image recognition, but I'd like to move into video after getting the basics down.

    (All personal project stuff)



  • I've looked into this (for reading an LED display with a cheap webcam) but haven't done anything yet. I'm planning to use OpenCV with the Emgu wrapper for C#.

    There are some tutorials on this site, they use a different wrapper through. The web seems to think Emgu is better than OpenCVSharp.

    The image clasifier one is probably the most relevant for you: http://www.learncomputervision.com/articles/programming/how-to-train-opencv-haar-classifiers/



  • For a quick start in C#, I had some success with AForge.NET (you're probably interested in AForge.Imaging specifically - here are some random links showcasing the features, and there should be some sample sources in the installation package).

    AFAIK AForge is much easier to use than OpenCV, and the docs are nicer, but it mostly focuses on image processing (filters, etc.) rather than computer vision algorithms. So it kind of depends what you plan to do - if all you need is some edge detection and a bit of logic on top of that, you should be fine with AForge, if you want facial recognition or other more advanced features, time to whip out OpenCV.



  • I wanted to do some testing using twitch video streams, looking for specific events that happen in game, or specific broadcaster scenes. All pretty experimental stuff.



  • If you can turn the problem into some variation of Twitch Plays _____ you may not even need any code.



  • Pretty sure they are busy trying to beat dark souls still.


  • :belt_onion:

    There is also a not well-known but very powerful library called dlib I have used. It performs better than OpenCV to detect faces (lower false positive). The code quality is certainly much better than OpenCV. It is C++11 and does not offer easy wrappers for C# however.



  • Sounds like it's not very useful for somebody looking for CV in c# then.


  • :belt_onion:

    I am sure you need first an algorithm, then you should implement it in whatever language you want. The hard part is algorithm not implementation. So you can test it in C++ or Python then use this only after you are certain it is the right fit.



  • Encog would be very usefull if you need some machine learning stuff with that http://www.heatonresearch.com/encog/



  • @Matches said:

    Sounds like it's not very useful for somebody looking for CV in c# then.

    You can P/Invoke it and basically write a managed wrapper yourself. It's not rocket science, and it'll likely give you a major performance boost over a 100% managed library (although a) your .NET library is probably a P/Invoke wrapper under the covers anyway, and b) marshalling between whatever bitmap format the library uses and System.Drawing.Bitmap might get a little bit tricky).

    May or may not be worth the hassle depending on whether you need the features.



  • If you think translating c++ code or pinvoking anything when there are existing c# libraries that you even mentioned that probably use the same or similar algorithms, you're
    Fucking nuts.



  • I concur. And "major performance boost" is really, really overstating the difference between C# and a fully-compiled language. Which is minimal.


  • Discourse touched me in a no-no place

    It might be possible to squeeze quite a bit more performance out of a C++ program than a C# program, but the amount of effort to do it means that it usually isn't worth the developer time. It's the old saw about optimization:

    1. Don't do it!
    2. Don't do it. Yet. (For experts only.)

    However, choosing a non-dumb algorithm and non-dumb data-structures is not optimization.



  • @blakeyrat said:

    I concur. And "major performance boost" is really, really overstating the difference between C# and a fully-compiled language. Which is minimal.

    Normally I'd agree, but managed bitmaps are... special.

    Algorithm Total Time (ms) % Difference
    unsafe 194 0
    IntPtr 262 35%
    GetPixel 238,299 (~4 min.) 122,734%

    You don't strictly need to leave C#, but you definitely need to leave the managed code.


  • Discourse touched me in a no-no place

    Discourse belgium­s the table if it contains blank lines or is quoted. :(

    Algorithm Total Time (ms) % Difference
    unsafe 194 0
    IntPtr 262 35%
    GetPixel 238,299 (~4 min.) 122,734%


  • Ah, that's the problem. Thanks, shamelessly stolen.


  • Winner of the 2016 Presidential Election

    @dkf said:

    blank lines

    Ah, yes, blank lines, BBCodeHTMarkdownL's only weakness!


  • Discourse touched me in a no-no place

    @Onyx said:

    Ah, yes, blank lines, BBCodeHTMarkdownL's only weakness!

    "My one weakness is blank lines, and underscores at the end of usernames. My two weaknesses are blank lines, underscores at the end of usernames, and a fanatical devotion to jellypotato. My three weaknesses are… I'll come in again.”



  • @Maciejasjmj said:

    You don't strictly need to leave C#, but you definitely need to leave the managed code.
    The problem with GetPixel is that under the covers it locks, marshals everything, converts the Color to the appropriate values based on the pixel format, copies, marshals everything, and unlocks. For each call. When using the IntPtr or unsafe method, the locking, marshaling, re-marshaling, and unlocking are only done once per batch, not once per pixel.



  • Hm, that is pretty crazy.

    Is there a version of GetPixel that doesn't do the color correction stuff? That'd probably run at least a bit better.



  • @Onyx said:

    BBCodeHTMarkdownL's

    Nice subliminal message.


  • Winner of the 2016 Presidential Election

    Someone get that man a spoon...



  • Stack overflow suggests this: http://stackoverflow.com/questions/24701703/c-sharp-faster-alternatives-to-setpixel-and-getpixel-for-bitmaps-for-windows-f

    Also, god dammit discourse, if I have a word highlighted in another post (OFF SCREEN EVEN) and click reply to another user, it tries to do a quote reply on the highlighted word instead of reply to the user I clicked the reply button for.



  • @dkf said:

    It might be possible to squeeze quite a bit more performance out of a C++ program than a C# program, but the amount of effort to do it means that it usually isn't worth the developer time

    That depends, it used to have a big difference with image processing if you use SIMD. Last time I used it wasn't available for C#, but it seems they have something now. GPUs are also very worth using for some things.


  • Discourse touched me in a no-no place

    @fbmac said:

    That depends, it used to have a big difference with image processing if you use SIMD. Last time I used it wasn't available for C#, but it seems they have something now. GPUs are also very worth using for some things.

    That falls into the exception implied by my “usually”. :smiley:


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.