topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 7:38 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: How to get started with Python and OpenCV?  (Read 6439 times)

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 9,778
    • View Profile
    • Read more about this member.
    • Donate to Member
How to get started with Python and OpenCV?
« on: April 26, 2018, 08:17 PM »
[EDIT] Originally posted in this thread: Dice analyzer machine project before being split off into its own thread. [/EDIT]

This is slightly off-topic so if you'd like me to start a new thread I'll do that, but...

I've been toying with an idea to write a little utility that would need to analyze a few words/numbers on the screen (or from a screenshot) and then make a decision and emulate some keyboard input based on that. The thing that's holding me back is that I'm concerned it will take me much more time and effort writing the utility than it would save me from just manually doing the thing I want to automate.

Do you have a recommendation or suggestion or ideas on the relative ease or difficulty it would be for someone like me who is familiar with coding but never really used Python or OpenCV before to get started on extracting data (essentially OCR with a very clear font) from an image?

I can go into more specific details if you'd like but I was attempting to keep this short to prevent myself from derailing this thread too far.
« Last Edit: April 27, 2018, 12:32 PM by Deozaan »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: How to get started with Python and OpenCV?
« Reply #1 on: April 26, 2018, 08:55 PM »
The thing that's holding me back is that I'm concerned it will take me much more time and effort writing the utility than it would save me from just manually doing the thing I want to automate.

This is always a concern, and an age old dilemma.  Part of the answer so such questions comes down to your personal distaste for doing repetitive manual actions.  Some of us coders have precious little patience for such things and would rather spend 10 hours coding a solution over 1 hour of manual data entry..

If you just have a finite number of times you have to do this, the manual way will probably be quicker.  But if you have to do it over and over for an indefinite amount of time..

Your first test might be to see how good the ocr reading works as that will likely be your biggest bottleneck.  If that works on, the rest should be fairly painless.
« Last Edit: April 27, 2018, 12:33 PM by Deozaan »

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 9,778
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: How to get started with Python and OpenCV?
« Reply #2 on: April 26, 2018, 09:18 PM »
Are there any resources you would recommend that would help me get started with setting up Python and OpenCV?

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: How to get started with Python and OpenCV?
« Reply #3 on: April 27, 2018, 11:01 AM »
Probably best to split this off into a separate thread.  There is a post about a nice beginner IDE (Thonny) for learning python: https://www.donation...ndex.php?topic=44811
But that may not be well suited to using a big library like OpenCV (I'm not sure).
I do think that learning OpenCV will serve you well.

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 9,778
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: How to get started with Python and OpenCV?
« Reply #4 on: April 27, 2018, 12:39 PM »
I split the thread off. Thanks for the suggestion!

I also found that Packt has a free eBook on Python and OpenCV: Learning OpenCV 3 Computer Vision with Python

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: How to get started with Python and OpenCV?
« Reply #5 on: May 08, 2018, 03:35 AM »
I dabble a bit in OpenCV and Python and have had most help from these three resources

1. https://www.pyimagesearch.com/
A great tutorial and project site with detailed, stepwise explainers of the code. The site has in the last year or so turned more and more to advanced machine learning topics, but check older posts for more introductory examples and projects.

Adrian Rosebrock, the pyimagesearch guy, also has a companion book https://www.pyimages...ctical-python-opencv  that seem useful, though I haven't read it.

2. https://opencv-pytho...ls/py_tutorials.html
Explainers and examples for many basic OpenCV functions in Python.

3. and, of course, https://stackoverflo...tagged/opencv+python

One thing to keep in mind: there are some differences between Python 2 and 3 when it comes to using and installing OpenCV. Last time I checked the most up to date release of OpenCV didn't play nice with with Python 3 in Windows 10.

But if you're on Python 3 you can quickly install a more basic version of OpenCV like so
python -m pip install numpy --upgrade
python -m pip install opencv-python --upgrade

I don't know exactly what that version is missing (the package page is here, https://pypi.org/project/opencv-python/ ) but it has worked well in all my use cases.

Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 9,778
    • View Profile
    • Read more about this member.
    • Donate to Member
Re: How to get started with Python and OpenCV?
« Reply #6 on: May 08, 2018, 04:02 PM »
This is one of those cases where I was asking for something specific (OpenCV+Python) when I really should have asked about OCR in general and seen what knowledge people had on the subject.

As mentioned in the OP, I wanted something that would allow me to analyze a screenshot for certain words and values and then make decisions based on that. It didn't necessarily have to be with OpenCV or Python. That was just the only way I knew of that made such an idea possible.

I'm much more familiar with C# and .NET so I decided to look for some sort of OpenCV wrapper that would allow me to program in C#. I found some, but while researching the topic further, I discovered that Microsoft has a Computer Vision library built in to the UWP SDK. So I can just have a line near the top of my code saying:

Code: C# [Select]
  1. using Windows.Media.Ocr;

And voila! I've got OCR in my C# code.

Of course, this also means that I need to build/deploy a UWP app, which I'm also not very familiar with, but at least it's using a language and environment I'm familiar with.


All that said, while experimenting with the Windows OCR, my immediate need for this whole project was accidentally fulfilled so I haven't been pursuing it at the moment. But if/when I pick it up again I'll probably start with UWP and if that doesn't work then I may look more into OpenCV again.

Thanks!

hamradio

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 884
  • Amateur Radio Guy
    • View Profile
    • HamRadioUSA.net
    • Read more about this member.
    • Donate to Member
Re: How to get started with Python and OpenCV?
« Reply #7 on: May 08, 2018, 04:22 PM »
This is one of those cases where I was asking for something specific (OpenCV+Python) when I really should have asked about OCR in general and seen what knowledge people had on the subject.

As mentioned in the OP, I wanted something that would allow me to analyze a screenshot for certain words and values and then make decisions based on that. It didn't necessarily have to be with OpenCV or Python. That was just the only way I knew of that made such an idea possible.

I'm much more familiar with C# and .NET so I decided to look for some sort of OpenCV wrapper that would allow me to program in C#. I found some, but while researching the topic further, I discovered that Microsoft has a Computer Vision library built in to the UWP SDK. So I can just have a line near the top of my code saying:

Code: C# [Select]
  1. using Windows.Media.Ocr;

And voila! I've got OCR in my C# code.

Of course, this also means that I need to build/deploy a UWP app, which I'm also not very familiar with, but at least it's using a language and environment I'm familiar with.


All that said, while experimenting with the Windows OCR, my immediate need for this whole project was accidentally fulfilled so I haven't been pursuing it at the moment. But if/when I pick it up again I'll probably start with UWP and if that doesn't work then I may look more into OpenCV again.

Thanks!

Just saw this topic but...

This OpenCV wrapper I found looks pretty good to me and I might have to make note to use it at some point down the road too: http://www.emgu.com/.../index.php/Main_Page

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,169
    • View Profile
    • Donate to Member
Re: How to get started with Python and OpenCV?
« Reply #8 on: May 08, 2018, 04:59 PM »
I found some, but while researching the topic further, I discovered that Microsoft has a Computer Vision library built in to the UWP SDK.

Whatever works! :Thmbsup: