Coder Social home page Coder Social logo

mbeyeler / opencv-python-blueprints Goto Github PK

View Code? Open in Web Editor NEW
291.0 291.0 184.0 188.56 MB

M. Beyeler (2015). OpenCV with Python Blueprints: Design and develop advanced computer vision projects using OpenCV with Python, Packt Publishing Ltd., ISBN 978-178528269-0.

License: GNU General Public License v3.0

Python 100.00%
computer-vision image-processing machine-learning opencv python

opencv-python-blueprints's People

Contributors

mbeyeler 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  avatar  avatar  avatar

opencv-python-blueprints's Issues

TypeError: only length-1 arrays can be converted to Python scalars

when I run the code chapter6.py

I got this error.

/usr/bin/python2.7 /home/redhwan/Downloads/opencv-python-blueprints-master/chapter6/chapter6.py
feature None
 - strategy one-vs-one
    - train
Traceback (most recent call last):
  File "/home/redhwan/Downloads/opencv-python-blueprints-master/chapter6/chapter6.py", line 77, in <module>
    main()
  File "/home/redhwan/Downloads/opencv-python-blueprints-master/chapter6/chapter6.py", line 44, in main
    MCS.fit(X_train, y_train)
  File "/home/redhwan/Downloads/opencv-python-blueprints-master/chapter6/classifiers.py", line 258, in fit
    params=self.params)
TypeError: only length-1 arrays can be converted to Python scalars

Process finished with exit code 1

as you see, python 2.7
opencv 3.3
please help me to fix this error.
Thank you in advance

Classification label not drawn above bounding box

Thanks to @G10DRAS:

I found another bug, which is related to putTextabove a detected face. x,y co-ordinate are missing in function.

chapter7.py
def _process_frame(self, frame):
........
                # draw label above bounding box
                cv2.putText(frame, str(label), (x, y - 20),
                            cv2.FONT_HERSHEY_COMPLEX, 1, (0, 255, 0), 2)

Chapter 2

Hi, I am trying to understand your code but keep getting an error that I can't quite get around.

I keep getting this error and I
user:~/opencv-python-blueprints/chapter2$ python chapter2.py
Could not open audio: -1
Traceback (most recent call last):
File "chapter2.py", line 93, in
main()
File "chapter2.py", line 87, in main
layout = KinectLayout(None, -1, 'Kinect Hand Gesture Recognition', capture)
File "/home/lpcs/opencv-python-blueprints/chapter2/gui.py", line 71, in init
self.bmp = wx.BitmapFromBuffer(self.imgWidth, self.imgHeight, frame)
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_gdi.py", line 856, in BitmapFromBuffer
return gdi._BitmapFromBuffer(width, height, dataBuffer)
ValueError: Invalid data buffer size.

could not align head

i am using opencv2 and python version 3.5.2
i had made some changes and now got some error as follows:

Warning: Testing is disabled
Could not find data file datasets/faces_preprocessed.pkl
Could not align head (eye detection failed?)

Test/update code for OpenCV3

Make sure code runs with OpenCV3. Update where necessary. Make it so that code works for both OpenCV2&3.

  • Fix CAP_PROP_FRAME_WIDTH (see issue #9)
  • Switch to print()
  • Check all chapters

Move common code out of chapters

For the sake of the book release all chapters are supposed to be self-contained. However, now that this code is on GitHub, it would make more sense to move common code (such as gui.py) out of chapter directories and into a common directory in order to avoid code duplication.

  • Create common module
  • Move gui.py
  • Move classifiers.py

Chapter 5: Error too many values to unpack

Using the sample video of Chapter 5, when it run, it produces error:
in main
sal.get_proto_objects_map(use_otsu=False)))

File "tracking.py", line 68, in advance_frame
box_all = self._append_boxes_from_saliency(proto_objects_map, box_all)

File "tracking.py", line 105, in _append_boxes_from_saliency
cnt_sal, _ = cv2.findContours(proto_objects_map, 1, 2)

ValueError: too many values to unpack

Fix code for Raspberry Pi

There are at least two issues on Raspberry Pi that need fixing:

  • cv2.VideoCapture(0) won't work
  • wxPython needs adjustments as suggested by G10DRAS

metaclass error for chapter7

When I ran code on Mac OS 10.12.3 with Python 2.7 I received following error for chapter7.py

bash-3.2$ python chapter7.py
Traceback (most recent call last):
  File "chapter7.py", line 33, in <module>
    from gui import BaseLayout
  File "/Users/jinay/workspace/upwork/opencv-python-blueprints/chapter7/gui.py", line 20, in <module>
    class BaseLayout(Meta1):
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/abc.py", line 87, in new
    cls = super(ABCMeta, mcls).__new__(mcls, name, bases, namespace)
TypeError: Error when calling the metaclass bases
    metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Possible work around could be #16

Cartoonizer on face with transparent background

I want to apply the Cartoonizer on a image with a transparent background. Sadly the alpha channel will always be removed and therefore all transparent parts are black after the filter was applied. Is there a workaround to fix this?

EDIT:
When I read in the image with alpha channels like this:
img = cv2.imread("frame004.png", cv2.IMREAD_UNCHANGED)

I get the following error:
OpenCV Error: Assertion failed ((src.type() == CV_8UC1 || src.type() == CV_8UC3) && src.type() == dst.type() && src.size() == dst.size() && src.data != dst.data) in bilateralFilter_8u, file /tmp/opencv-20161221-94455-1gogyaj/opencv-2.4.13.2/modules/imgproc/src/smooth.cpp, line 1925 Traceback (most recent call last): File "cartoonizer.py", line 17, in <module> frame_cartooned = cartoonizer.render(img) File "/Users/oliverweiss/dev/cartoonizer/filters.py", line 163, in render img_color = cv2.bilateralFilter(img_color, 9, 9, 7) cv2.error: /tmp/opencv-20161221-94455-1gogyaj/opencv-2.4.13.2/modules/imgproc/src/smooth.cpp:1925: error: (-215) (src.type() == CV_8UC1 || src.type() == CV_8UC3) && src.type() == dst.type() && src.size() == dst.size() && src.data != dst.data in function bilateralFilter_8u

Thank you!

Bug for mac

Hi-
Chapter7.py : In mac the UI/window does not show up. However, in Ubuntu 14.04 64 bit machine with all the similar package versions but it seems that there it is working fine. Maybe this is because of gui.py or wxpython package in mac (I installed all of them using brew). Chapter3 code as well I am getting same issue.

In details, there is a infinite loop at App:init: line 1870 self._BootstrapApp() in core.py
/usr/local/lib/python2.7/site-packages/wx/core.py
Which basically tells that upon completion of this function OnInit() function will be called which should be available in derived class of App.

Chapter 1, filters.py OpenCV error

I am trying to run the cartoonify code

import cv2
import numpy as np

numDownSamples = 2       # number of downscaling steps
numBilateralFilters = 7  # number of bilateral filtering steps

img_rgb = cv2.imread("testimg.jpg")

# -- STEP 1 --
# downsample image using Gaussian pyramid
img_color = img_rgb
for _ in range(numDownSamples):
    img_color = cv2.pyrDown(img_color)

# repeatedly apply small bilateral filter instead of applying
# one large filter
for _ in range(numBilateralFilters):
    img_color = cv2.bilateralFilter(img_color, 9, 9, 7)

# upsample image to original size
for _ in range(numDownSamples):
    img_color = cv2.pyrUp(img_color)

# -- STEPS 2 and 3 --
# convert to grayscale and apply median blur
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2GRAY)
img_blur = cv2.medianBlur(img_gray, 7)

# -- STEP 4 --
# detect and enhance edges
img_edge = cv2.adaptiveThreshold(img_blur, 255,
                                    cv2.ADAPTIVE_THRESH_MEAN_C,
                                    cv2.THRESH_BINARY, 9, 2)

# -- STEP 5 --
# convert back to color so that it can be bit-ANDed with color image
img_edge = cv2.cvtColor(img_edge, cv2.COLOR_GRAY2RGB)
toon = cv2.bitwise_and(img_color, img_edge)
cv2.imwrite('cartoon.jpg', toon)

When I run it however I get the following error

OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array') in cv::binary_op, file C:\projects\opencv-python\opencv\modules\core\src\arithm.cpp, line 225
Traceback (most recent call last):
  File "cartoonify.py", line 38, in <module>
    toon = cv2.bitwise_and(img_color, img_edge)
cv2.error: C:\projects\opencv-python\opencv\modules\core\src\arithm.cpp:225: error: (-209) The operation is neither 'array op array' (where arrays have the same size and type), nor 'array op scalar', nor 'scalar op array' in function cv::binary_op

I am running python 3.6
numpy==1.14.2
opencv-python==3.4.0.12
Pillow==5.1.0

Any ideas on how I can get this working?

capture.set(cv2.CV_CAP_PROP_FRAME_HEIGHT, 480) ----> does not work in opencv3

Hi- it seems that " capture.set(cv2.CV_CAP_PROP_FRAME_HEIGHT, 480)" does not work with opencv3. I see the following error:

File "chapter7.py", line 293, in
main()
File "chapter7.py", line 282, in main
capture.set(cv2.CV_CAP_PROP_FRAME_HEIGHT, 480)
AttributeError: 'module' object has no attribute 'CV_CAP_PROP_FRAME_HEIGHT'

I use python 2.7 and followed the following link for installation:
http://www.pyimagesearch.com/2016/12/19/install-opencv-3-on-macos-with-homebrew-the-easy-way/

wxPython can't be installed on Mac OS X 10.11 El Capitan

This is not a problem with the book code itself, but with the wxPython package, which is required for most chapters.

Apparently it's impossible to install wxPython on Mac OS X 10.11 El Capitan via common practices, resulting in the following error:

“wxPython3.0-osx-cocoa-py2.7.pkg” is damaged and can’t be opened. You should eject the disk image.

The bug is documented here:
http://stackoverflow.com/questions/34402303/install-wxpython-in-osx-10-11

There seems to be a workaround here:
http://davixx.fr/blog/2016/01/25/wxpython-on-os-x-el-capitan/

Try to get confirmation that the workaround works. Has anyone tried this??

If it works, include instructions in the doc to resolve this nasty issue, so that users won't get stuck in the future.

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.