Git Product home page Git Product logo

learning-opencv-4-computer-vision-with-python-third-edition's Introduction

Learning OpenCV 4 Computer Vision with Python 3 - Third Edition

Learning OpenCV 4 Computer Vision with Python 3 - Third Edition

This is the code repository for Learning OpenCV 4 Computer Vision with Python 3 - Third Edition, published by Packt.

Get to grips with tools, techniques, and algorithms for computer vision and machine learning

What is this book about?

Computer vision is a rapidly evolving science, encompassing diverse applications and techniques. This book will not only help those who are getting started with computer vision but also experts in the domain. You’ll be able to put theory into practice by building apps with OpenCV 4 and Python 3.

This book covers the following exciting features:

  • Install and familiarize yourself with OpenCV 4's Python 3 bindings
  • Understand image processing and video analysis basics
  • Use a depth camera to distinguish foreground and background regions
  • Detect and identify objects, and track their motion in videos
  • Train and use your own models to match images and classify objects
  • Detect and recognize faces, and classify their gender and age
  • Build an augmented reality application to track an image in 3D
  • Work with machine learning models, including SVMs, artificial neural networks(ANNs), and deep neural networks(DNNs)

If you feel this book is for you, get your copy today!

https://www.packtpub.com/

Instructions and Navigations

All of the code is organized into folders. For example, Chapter02.

The code will look like the following:

import cv2

grayImage = cv2.imread('MyPic.png', cv2.IMREAD_GRAYSCALE)
cv2.imwrite('MyPicGray.png', grayImage)

Following is what you need for this book: If you are interested in learning computer vision, machine learning, and OpenCV in the context of practical real-world applications, then this book is for you. This OpenCV book will also be useful for anyone getting started with computer vision as well as experts who want to stay up-to-date with OpenCV 4 and Python 3. Although no prior knowledge of image processing, computer vision or machine learning is required, familiarity with basic Python programming is a must.

We provide a PDF file that has color images of the screenshots/diagrams used in this book. Click here to download it.

With the following software and hardware list you can run all code files present in the book (Chapter 1-10).

Software and Hardware List

Chapter Software required OS required
1-10 Python 3 (specifically, 3.5 or later) Windows, Mac OS X, and Linux (Any)
1-10 OpenCV 4 Windows, Mac OS X, and Linux (Any)
1-10 NumPy (any recent version) Windows, Mac OS X, and Linux (Any)
3 SciPy (any recent version) Windows, Mac OS X, and Linux (Any)
4, 5 OpenNI 2 Windows, Mac OS X, and Linux (Any)
4, 6 Matplotlib (any recent version) Windows, Mac OS X, and Linux (Any)

Errata

  • Page 244: Code should be
    for c in contours:
    if cv2.contourArea(c) > 500:
    (x, y, w, h) = cv2.boundingRect(c)
    cv2.rectangle(frame, (x, y), (x+w, y+h),
    (0, 255, 0), 1)
    if should_initialize_pedestrians:
    pedestrians.append(
    Pedestrian(id, hsv_frame,
    (x, y, w, h)))
    id += 1
    

Update about Optional Software Requirements

At the time the book was written, some of the code samples (in Chapters 6 and 7) depended on OpenCV's "non-free" modules in order to use the SIFT and SURF patented algorithms. Since then, the SIFT patent has expired and, starting in OpenCV 4.4.0, SIFT can be used without the "non-free" modules. There is now just one code sample (in Chapter 6) which depends on the "non-free" modules for SURF. If you wish to try the SURF sample, you will need to build OpenCV with the "non-free" modules from source (as per instructions in Chapter 1 for building from source). The pre-built opencv-contrib-python-nonfree pip package (also mentioned in Chapter 1) is no longer available.

Related Products

Get to Know the Authors

Joseph Howse lives in a Canadian fishing village with four cats; the cats like fish, but they prefer chicken.

Joseph provides computer vision expertise through his company, Nummist Media. His books include OpenCV 4 for Secret Agents, Learning OpenCV 4 Computer Vision with Python 3, OpenCV 3 Blueprints, Android Application Programming with OpenCV 3, iOS Application Development with OpenCV 3, and Python Game Programming by Example, published by Packt.

Joe Minichino is an R&D labs engineer at Teamwork. He is a passionate programmer who is immensely curious about programming languages and technologies and constantly experimenting with them. Born and raised in Varese, Lombardy, Italy, and coming from a humanistic background in philosophy (at Milan's Università Statale), Joe has lived in Cork, Ireland, since 2004. There, he became a computer science graduate at the Cork Institute of Technology.

Troubleshooting and FAQ

Issue: Camera input does not work on Windows

For some cameras and some versions of OpenCV, cv2.VideoCapture fails to capture camera input when it uses the Microsoft Media Foundation (MSMF) back-end. This issue may manifest itself with errors such as [ WARN:[email protected]] global C:\opencv\modules\videoio\src\cap_msmf.cpp (539) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback when you run camera input scripts such as chapter02/5-CameraWindow.py.

To work around the problem, define an environment variable with the name OPENCV_VIDEOIO_PRIORITY_MSMF and the value 0. (You may need to reboot in order for global changes to your environment variables to take effect.) This change de-prioritizes OpenCV's MSMF back-end so that OpenCV will try to choose any other back-end, usually the Microsoft DirectShow back-end, which is more compatible.

Alternatively, to specify the preferred back-end in any given script, replace code such as cv2.VideoCapture(0) with code such as cv2.VideoCapture(0, cv2.CAP_DSHOW), which specifies Microsoft DirectShow as the preferred back-end. However, be aware that such changes may reduce the portability of your code.

Question: Will the sample code work with the upcoming OpenCV 5?

The sample code in this repository has been tested successfully with OpenCV's 5.x development branch as of August 7, 2022. Thus, as far as we can tell at this point, it should work with the upcoming OpenCV 5 release.

A future edition of the book will provide more extensive coverage of new features in OpenCV 5. See https://github.com/PacktPublishing/Learning-OpenCV-5-Computer-Vision-with-Python-Fourth-Edition.

Suggestions and Feedback

Click here if you have any feedback or suggestions.

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781789531619

learning-opencv-4-computer-vision-with-python-third-edition's People

Contributors

aleksandergali avatar ankona avatar digvijay-b avatar joehowse avatar jubit-packt avatar ketankamble avatar packt-itservice avatar packtutkarshr avatar sonkaryasshu avatar techfort avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learning-opencv-4-computer-vision-with-python-third-edition's Issues

ndimage convolve

kernel_3x3 = np.array([[-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]])

kernel_5x5 = np.array([[-1, -1, -1, -1, -1],
[-1, 1, 2, 1, -1],
[-1, 2, 4, 2, -1],
[-1, 1, 2, 1, -1],
[-1, -1, -1, -1, -1]])

img = cv2.imread("../images/statue_small.jpg", 0)

k3 = ndimage.convolve(img, kernel_3x3)
k5 = ndimage.convolve(img, kernel_5x5)

have a problem:

File "C:\Users\xxxxx\anaconda3\lib\site-packages\scipy\ndimage\filters.py", line 605, in _correlate_or_convolve
raise RuntimeError('filter weights array has incorrect shape.')

RuntimeError: filter weights array has incorrect shape.

The `frame` method in managers.py has a bug

The cameo code doesn't work unless the frame method in managers.py is updated as:

@property
def frame(self):
    if self._enteredFrame:
        _, self._frame = self._capture.retrieve(self._enteredFrame, self.channel)
        return self._frame

Problem compiling OpenCV with VStudio

Dear Forum

Following the book instruction, i load in VS the OpenCV.sln , select - Release - x64, and build.

The build process show me 183 steps, all ok apart 1, the 134, that give me this fatal error:

134>C:\OpenCV\opencv\sources\modules\python\src2\cv2.cpp(17,10): fatal error C1083: Cannot open include file: 'Python.h': No such file or directory
134>Done building project "opencv_python3.vcxproj" -- FAILED.

The total result is this:
= Build: 172 succeeded, 1 failed, 0 up-to-date, 10 skipped ====

Other info:
The OpenVC is the 4.5.4.
VS is the comunity 2019
Python 3.10.2 (tipyng python on terminal i get this reply)

So, what can i do.
Thanks
Roberto

Modifying for different OpenNI compliant devices

Hello,
I have been enjoying your book and learning alot from it. But I have become stuck trying to understand how to modify the code for a different openni camera. A significant part is my own ignorance around drilling back through the stack to understand what is being called from where. I am not even sure which OpenCV is being called... Maybe a good Packt course would be understanding and using Visual Studio Code or other programming environment to allow understanding of the software stack.
Thanks.

no module named typing

from typing import List, Optional
ImportError: No module named typing

I'm getting this error when I'm trying to use any pip install command.
I tried using pip install typing in the terminal too but it isn't working.
Looking forward to hearing from you on this

I'm using MacBook Air apple chip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.