Un día del año pasado quise jugar con el framework opencv, basicamente es un framework para trabajar con visión artificial hecho en python. A mí me pareció muy farragoso y difícil de manejar, debido a mi inexperiencia con python.

A ver si un día lo retomo, pero esta vez bajando una imagen docker con todo configurado.

Estos son los comandos que lancé para instalar el framework y para ejecutar algunos ejemplos. Muy potente.

aironman@MacBook-Pro-de-Alonso ~> python3
Python 3.7.5 (default, Nov 1 2019, 02:16:23)
[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

exit
Use exit() or Ctrl-D (i.e. EOF) to exit
exit()
aironman@MacBook-Pro-de-Alonso ~> which python3

/usr/local/bin/python3

aironman@MacBook-Pro-de-Alonso ~> brew install cmake pkg-config

==> Downloading https://homebrew.bintray.com/bottles/cmake-3.16.2.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/7b/7b7d0cc5ceba524f0bea36285ab0cf5e23afc79b71633018ae504c22a32eaf0a?gda=exp=1578503611~hmac=d46e8d639b2c396bb50697d17572a9a5b4bec6d4c9fc904540b96ef30b714a44&response-content-disposition=
#######################################################################100.0%

aironman@MacBook-Pro-de-Alonso ~> brew install jpeg libpng libtiff openexr
aironman@MacBook-Pro-de-Alonso ~> brew install wget
aironman@MacBook-Pro-de-Alonso ~> sudo pip3 install virtualenv virtualenvwrapper
aironman@MacBook-Pro-de-Alonso ~> sudo rm -rf ~/get-pip.py ~/.cache/pip
aironman@MacBook-Pro-de-Alonso ~> nano ~/.bash_profile
aironman@MacBook-Pro-de-Alonso ~> vi ~/.bash_profile
aironman@MacBook-Pro-de-Alonso ~> source ~/.bash_profile

#
Project home page: http://www.doughellmann.com/projects/virtualenvwrapper/
#
#
Setup:
#

  1. Create a directory to hold the virtual environments.
    (mkdir $HOME/.virtualenvs).
  2. Add a line like “export WORKON_HOME=$HOME/.virtualenvs”
    to your .bashrc.
  3. Add a line like “source /path/to/this/file/virtualenvwrapper.sh”
    to your .bashrc.
  4. Run: source ~/.bashrc
  5. Run: workon
  6. A list of environments, empty, is printed.
  7. Run: mkvirtualenv temp
  8. Run: workon
  9. This time, the “temp” environment is included.
  10. Run: workon temp
  11. The virtual environment is activated.
    #

aironman@MacBook-Pro-de-Alonso ~> bash
aironman@MacBook-Pro-de-Alonso ~ % /usr/local/bin/virtualenvwrapper.sh
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.

If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.

aironman@MacBook-Pro-de-Alonso ~ % export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
aironman@MacBook-Pro-de-Alonso ~ % export WORKON_HOME=$HOME/.virtualenvs
aironman@MacBook-Pro-de-Alonso ~ % source /usr/local/bin/virtualenvwrapper.sh
aironman@MacBook-Pro-de-Alonso ~ % mkvirtualenv cv -p python3
Running virtualenv with interpreter /usr/local/bin/python3
Already using interpreter /usr/local/opt/python/bin/python3.7
Using base prefix ‘/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7’
New python executable in /Users/aironman/.virtualenvs/cv/bin/python3.7
Also creating executable in /Users/aironman/.virtualenvs/cv/bin/python
Installing setuptools, pip, wheel…
done.
virtualenvwrapper.user_scripts creating /Users/aironman/.virtualenvs/cv/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/aironman/.virtualenvs/cv/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/aironman/.virtualenvs/cv/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/aironman/.virtualenvs/cv/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/aironman/.virtualenvs/cv/bin/get_env_details
(cv) aironman@MacBook-Pro-de-Alonso ~ % workon cv
(cv) aironman@MacBook-Pro-de-Alonso ~ % pip install numpy
Collecting numpy
Downloading https://files.pythonhosted.org/packages/2f/5b/2cc2b9285e8b2ca8d2c1e4a2cbf1b12d70a2488ea78170de1909bca725f2/numpy-1.18.1-cp37-cp37m-macosx_10_9_x86_64.whl (15.1MB)
|████████████████████████████████| 15.1MB 442kB/s
Installing collected packages: numpy
Successfully installed numpy-1.18.1
(cv) aironman@MacBook-Pro-de-Alonso ~ % wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.0.zip
–2020-01-08 18:12:31– https://github.com/opencv/opencv/archive/4.0.0.zip
Resolviendo github.com (github.com)… 140.82.118.3
Conectando con github.com (github.com)[140.82.118.3]:443… conectado.
Petición HTTP enviada, esperando respuesta… 302 Found
Localización: https://codeload.github.com/opencv/opencv/zip/4.0.0 [siguiendo]
–2020-01-08 18:12:32– https://codeload.github.com/opencv/opencv/zip/4.0.0
Resolviendo codeload.github.com (codeload.github.com)… 140.82.114.9
Conectando con codeload.github.com (codeload.github.com)[140.82.114.9]:443… conectado.
Petición HTTP enviada, esperando respuesta… 200 OK
Longitud: 91053596 (87M) [application/zip]
Grabando a: “opencv.zip”

opencv.zip 100%[=========================================================================================================================================>] 86,83M 4,59MB/s en 26s

2020-01-08 18:12:59 (3,29 MB/s) – “opencv.zip” guardado [91053596/91053596]

(cv) aironman@MacBook-Pro-de-Alonso ~ % wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.0.0.zip
–2020-01-08 18:13:20– https://github.com/opencv/opencv_contrib/archive/4.0.0.zip
Resolviendo github.com (github.com)… 140.82.118.4
Conectando con github.com (github.com)[140.82.118.4]:443… conectado.
Petición HTTP enviada, esperando respuesta… 302 Found
Localización: https://codeload.github.com/opencv/opencv_contrib/zip/4.0.0 [siguiendo]
–2020-01-08 18:13:20– https://codeload.github.com/opencv/opencv_contrib/zip/4.0.0
Resolviendo codeload.github.com (codeload.github.com)… 140.82.113.9
Conectando con codeload.github.com (codeload.github.com)[140.82.113.9]:443… conectado.
Petición HTTP enviada, esperando respuesta… 200 OK
Longitud: no especificado [application/zip]
Grabando a: “opencv_contrib.zip”

opencv_contrib.zip [ <=> ] 58,61M 3,77MB/s en 18s

2020-01-08 18:13:39 (3,28 MB/s) – “opencv_contrib.zip” guardado [61452686]

(cv) aironman@MacBook-Pro-de-Alonso ~ % unzip opencv.zip

Archive: opencv.zip
75ed282b20770a7a9b490102fd2e0b4fa26223e5

(cv) aironman@MacBook-Pro-de-Alonso ~ % unzip opencv_contrib.zip

Archive: opencv_contrib.zip
d511587cf0bc782022db215d20d960afb2e9efe2

(cv) aironman@MacBook-Pro-de-Alonso ~ % mv opencv-4.0.0 opencv
(cv) aironman@MacBook-Pro-de-Alonso ~ % mv opencv_contrib-4.0.0 opencv_contrib
(cv) aironman@MacBook-Pro-de-Alonso ~ % cd ~/opencv
(cv) aironman@MacBook-Pro-de-Alonso opencv % mkdir build
(cv) aironman@MacBook-Pro-de-Alonso opencv % cd build
(cv) aironman@MacBook-Pro-de-Alonso build % workon cv
(cv) aironman@MacBook-Pro-de-Alonso build % cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D PYTHON3_LIBRARY=python -c 'import subprocess ; import sys ; s = subprocess.check_output("python-config --configdir", shell=True).decode("utf-8").strip() ; (M, m) = sys.version_info[:2] ; print("{}/libpython{}.{}.dylib".format(s, M, m))' \
-D PYTHON3_INCLUDE_DIR=python -c 'import distutils.sysconfig as s; print(s.get_python_inc())' \
-D PYTHON3_EXECUTABLE=$VIRTUAL_ENV/bin/python \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_EXAMPLES=ON ..

— Build files have been written to: /Users/aironman/opencv/build
(cv) aironman@MacBook-Pro-de-Alonso build %
(cv) aironman@MacBook-Pro-de-Alonso build % make

(cv) aironman@MacBook-Pro-de-Alonso build % sudo make install

Password:

(cv) aironman@MacBook-Pro-de-Alonso build % workon cv
(cv) aironman@MacBook-Pro-de-Alonso build % python –version

Python 3.7.6

(cv) aironman@MacBook-Pro-de-Alonso build % ls /usr/local/python/cv2/python-3.7

cv2.cpython-37m-darwin.so

(cv) aironman@MacBook-Pro-de-Alonso build % cd /usr/local/python/cv2/python-3.7
(cv) aironman@MacBook-Pro-de-Alonso python-3.7 % sudo mv cv2.cpython-37m-darwin.so cv2.so
(cv) aironman@MacBook-Pro-de-Alonso python-3.7 % cd ~/.virtualenvs/cv/lib/python3.7/site-packages
(cv) aironman@MacBook-Pro-de-Alonso site-packages % ln -s /usr/local/python/cv2/python-3.7/cv2.so cv2.so
(cv) aironman@MacBook-Pro-de-Alonso site-packages % pip install imutils

(cv) aironman@MacBook-Pro-de-Alonso site-packages % python

Python 3.7.6 (default, Dec 30 2019, 19:38:26)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

import cv2

cv2.version Traceback (most recent call last): File “”, line 1, in AttributeError: module ‘cv2’ has no attribute ‘__version’ cv2.__version
‘4.0.0’
exit()

(cv) aironman@MacBook-Pro-de-Alonso site-packages % unzip document-scanner.zip

unzip: cannot find or open document-scanner.zip, document-scanner.zip.zip or document-scanner.zip.ZIP.

(cv) aironman@MacBook-Pro-de-Alonso site-packages % tree

zsh: command not found: tree

(cv) aironman@MacBook-Pro-de-Alonso site-packages % pwd

/Users/aironman/.virtualenvs/cv/lib/python3.7/site-packages

cv) aironman@MacBook-Pro-de-Alonso .virtualenvs % which python3

/Users/aironman/.virtualenvs/cv/bin/python3

(cv) aironman@MacBook-Pro-de-Alonso .virtualenvs % cd /Users/aironman/Downloads/opencv-4.2.0/samples/python

(cv) aironman@MacBook-Pro-de-Alonso python % ls

CMakeLists.txt deconvolution.py floodfill.py lk_track.py stitching.py
_coverage.py demo.py gabor_threads.py logpolar.py stitching_detailed.py
_doc.py dft.py gaussian_mix.py morphology.py texture_flow.py
_run_winpack_demo.cmd digits.py grabcut.py mosse.py tst_scene_render.py
asift.py digits_adjust.py hist.py mouse_and_match.py turing.py
browse.py digits_video.py houghcircles.py mser.py tutorial_code
calibrate.py dis_opt_flow.py houghlines.py opencv_version.py video.py
camera_calibration_show_extrinsics.py distrans.py inpaint.py opt_flow.py video_threaded.py
camshift.py edge.py kalman.py peopledetect.py video_v4l2.py
coherence.py facedetect.py kmeans.py plane_ar.py watershed.py
color_histogram.py feature_homography.py lappyr.py plane_tracker.py
common.py find_obj.py letter_recog.py squares.py
contours.py fitline.py lk_homography.py stereo_match.py

FINALLY, i got all up and able to run samples!

(cv) aironman@MacBook-Pro-de-Alonso python % python camshift.py

Camshift tracker
================

This is a demo that shows mean-shift based tracking
You select a color objects such as your face and it tracks it.
This reads from video camera (0 by default, or the camera number the user enters)

[1] http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.14.7673

Usage:


  camshift.py [<video source>]

  To initialize tracking, select the object with mouse

Keys:


  ESC   - exit
  b     - toggle back-projected probability visualization

(cv) aironman@MacBook-Pro-de-Alonso python % python demo.py

DEPRECATION WARNING: The system version of Tk is deprecated and may be removed in a future release. Please don’t rely on it. Set TK_SILENCE_DEPRECATION=1 to suppress this warning.
2020-01-09 16:36:23.359 python[56641:4530120] CoreText note: Client requested name “.SFNSMono-Regular”, it will get Times-Roman rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].
2020-01-09 16:36:23.359 python[56641:4530120] CoreText note: Set a breakpoint on CTFontLogSystemFontNameRequest to debug.
2020-01-09 16:36:23.400 python[56641:4530120] CoreText note: Client requested name “.SF NS Mono”, it will get Times-Roman rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[NSFont systemFontOfSize:].

running: facedetect.py

face detection using haar cascades

USAGE:
facedetect.py [–cascade ] [–nested-cascade ] []

[ WARN:0] cv::samples::findFile(‘data/haarcascades/haarcascade_frontalface_alt.xml’) => ‘/Users/aironman/Downloads/opencv-4.2.0/samples/python/../../data/haarcascades/haarcascade_frontalface_alt.xml’
[ WARN:0] cv::samples::findFile(‘data/haarcascades/haarcascade_eye.xml’) => ‘/Users/aironman/Downloads/opencv-4.2.0/samples/python/../../data/haarcascades/haarcascade_eye.xml’
[ WARN:0] cv::samples::findFile(‘samples/data/lena.jpg’) => ‘/Users/aironman/Downloads/opencv-4.2.0/samples/python/../../samples/data/lena.jpg’
Done

running: asift.py

Affine invariant feature-based image matching sample.

This sample is similar to find_obj.py, but uses the affine transformation
space sampling technique, called ASIFT [1]. While the original implementation
is based on SIFT, you can try to use SURF or ORB detectors instead. Homography RANSAC
is used to reject outliers. Threading is used for faster affine sampling.

[1] http://www.ipol.im/pub/algo/my_affine_sift/

USAGE
asift.py [–feature=[-flann]] [ ]

–feature – Feature to use. Can be sift, surf, orb or brisk. Append ‘-flann’
to feature name to use Flann-based matcher instead bruteforce.

Press left mouse button on a feature point to see its matching point.

[ WARN:0] cv::samples::findFile(‘aero1.jpg’) => ‘/Users/aironman/Downloads/opencv-4.2.0/samples/python/../../samples/data/aero1.jpg’
[ WARN:0] cv::samples::findFile(‘aero3.jpg’) => ‘/Users/aironman/Downloads/opencv-4.2.0/samples/python/../../samples/data/aero3.jpg’
using brisk-flann
affine sampling: 43 / 43
affine sampling: 43 / 43
img1 – 39500 features, img2 – 24714 features
matching …
2549.15 ms
59 / 125 inliers/matched

(cv) aironman@MacBook-Pro-de-Alonso python %
(cv) aironman@MacBook-Pro-de-Alonso python %
(cv) aironman@MacBook-Pro-de-Alonso python % exit()
function>
function>
function>
function>
function>
function> workon cv

(cv) aironman@MacBook-Pro-de-Alonso python % python facedetect.py

face detection using haar cascades

USAGE:
facedetect.py [–cascade ] [–nested-cascade ] []

[ WARN:0] cv::samples::findFile(‘data/haarcascades/haarcascade_frontalface_alt.xml’) => ‘/Users/aironman/Downloads/opencv-4.2.0/samples/python/../../data/haarcascades/haarcascade_frontalface_alt.xml’
[ WARN:0] cv::samples::findFile(‘data/haarcascades/haarcascade_eye.xml’) => ‘/Users/aironman/Downloads/opencv-4.2.0/samples/python/../../data/haarcascades/haarcascade_eye.xml’
[ WARN:0] cv::samples::findFile(‘samples/data/lena.jpg’) => ‘/Users/aironman/Downloads/opencv-4.2.0/samples/python/../../samples/data/lena.jpg’
^[Done

(cv) aironman@MacBook-Pro-de-Alonso python % vi facedetect.py
(cv) aironman@MacBook-Pro-de-Alonso python % python turing.py

Multiscale Turing Patterns generator

Inspired by http://www.jonathanmccabe.com/Cyclic_Symmetric_Multi-Scale_Turing_Patterns.pdf

USAGE: turing.py [-o ]

Press ESC to stop.

Done
(cv) aironman@MacBook-Pro-de-Alonso python % python peopledetect.py

example to detect upright people in images using HOG features

Usage:
peopledetect.py

Press any key to continue, ESC to stop.

[ WARN:0] cv::samples::findFile(‘basketball2.png’) => ‘/Users/aironman/Downloads/opencv-4.2.0/samples/python/../../samples/data/basketball2.png’
/Users/aironman/Downloads/opencv-4.2.0/samples/python/../../samples/data/basketball2.png –
2 (2) found
Done

(cv) aironman@MacBook-Pro-de-Alonso python % python peopledetect.py /Users/aironman/Downloads/opencv-tutorial/jp.png

example to detect upright people in images using HOG features

Usage:
peopledetect.py

Press any key to continue, ESC to stop.

/Users/aironman/Downloads/opencv-tutorial/jp.png –
1 (1) found
Done
(cv) aironman@MacBook-Pro-de-Alonso python % python mouse_and_match.py

mouse_and_match.py [-i path | –input path: default ../data/]

Demonstrate using a mouse to interact with an image:
Read in the images in a directory one by one
Allow the user to select parts of an image with a mouse
When they let go of the mouse, it correlates (using matchTemplate) that patch with the image.

SPACE for next image
ESC to exit

../data/left09.jpg
../data/licenseplate_motion.jpg
../data/fruits.jpg
../data/gradient.png
../data/left08.jpg
../data/sudoku.png
../data/lena.jpg
../data/imageTextR.png
../data/smarties.png
Done
(cv) aironman@MacBook-Pro-de-Alonso python % pwd
/Users/aironman/Downloads/opencv-4.2.0/samples/python
(cv) aironman@MacBook-Pro-de-Alonso python %

Another session working with opencv

aironman@MacBook-Pro-de-Alonso ~/D/document-scanner> bash

The default interactive shell is now zsh.
To update your account to use zsh, please run chsh -s /bin/zsh.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2$ workon
bash: workon: command not found
bash-3.2$ export WORKON_HOME=$HOME/.virtualenvs
bash-3.2$ export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
bash-3.2$ source /usr/local/bin/virtualenvwrapper.sh
bash-3.2$ workon cv
(cv) bash-3.2$ python
Python 3.7.6 (default, Dec 30 2019, 19:38:26)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

import cv2
cv2.version
‘4.0.0’
exit()
(cv) bash-3.2$ cd document-scanner
bash: cd: document-scanner: No such file or directory
(cv) bash-3.2$ pwd
/Users/aironman/Downloads/document-scanner
(cv) bash-3.2$ tree
bash: tree: command not found
(cv) bash-3.2$ exit
exit
aironman@MacBook-Pro-de-Alonso ~/D/document-scanner> cd ..
aironman@MacBook-Pro-de-Alonso ~/Downloads> workon cv
fish: Unknown command workon
aironman@MacBook-Pro-de-Alonso ~/Downloads> bash

The default interactive shell is now zsh.
To update your account to use zsh, please run chsh -s /bin/zsh.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2$ workon cv
bash: workon: command not found
bash-3.2$ export WORKON_HOME=$HOME/.virtualenvs
bash-3.2$ export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
bash-3.2$ sh /usr/local/bin/virtualenvwrapper.sh
bash-3.2$ workon cv
bash: workon: command not found
bash-3.2$ source /usr/local/bin/virtualenvwrapper.sh
bash-3.2$ workon cv

(cv) bash-3.2$ cd document-scanner/
(cv) bash-3.2$ ls
images pyimagesearch scan.py
(cv) bash-3.2$ pip install scikit-image imutils
Collecting scikit-image
Downloading https://files.pythonhosted.org/packages/f7/c5/d2625858ffcc0b5a86557200224be9f1f22a71e5234563d218b6153fb635/scikit_image-0.16.2-cp37-cp37m-macosx_10_6_intel.whl (30.3MB)
|████████████████████████████████| 30.3MB 584kB/s
Requirement already satisfied: imutils in /Users/aironman/.virtualenvs/cv/lib/python3.7/site-packages (0.5.3)
Collecting matplotlib!=3.0.0,>=2.0.0
Downloading https://files.pythonhosted.org/packages/a0/76/68bc3374ffa2d8d3dfd440fe94158fa8aa2628670fa38bdaf186c9af0d94/matplotlib-3.1.2-cp37-cp37m-macosx_10_9_x86_64.whl (13.2MB)
|████████████████████████████████| 13.2MB 717kB/s
Collecting pillow>=4.3.0
Downloading https://files.pythonhosted.org/packages/0c/43/b52847e473ac6cbd10a749b63018b2bb08b55c6e1a1923872361443906de/Pillow-7.0.0-cp37-cp37m-macosx_10_6_intel.whl (3.9MB)
|████████████████████████████████| 3.9MB 839kB/s
Collecting networkx>=2.0
Downloading https://files.pythonhosted.org/packages/41/8f/dd6a8e85946def36e4f2c69c84219af0fa5e832b018c970e92f2ad337e45/networkx-2.4-py3-none-any.whl (1.6MB)
|████████████████████████████████| 1.6MB 11.5MB/s
Collecting scipy>=0.19.0
Downloading https://files.pythonhosted.org/packages/85/7a/ae480be23b768910a9327c33517ced4623ba88dc035f9ce0206657c353a9/scipy-1.4.1-cp37-cp37m-macosx_10_6_intel.whl (28.4MB)
|████████████████████████████████| 28.4MB 413kB/s
Collecting PyWavelets>=0.4.0
Downloading https://files.pythonhosted.org/packages/61/e7/b35d14bf5416e771764dd6e35b522cb2c02de02cdac493e509751b0be18f/PyWavelets-1.1.1-cp37-cp37m-macosx_10_9_x86_64.whl (4.3MB)
|████████████████████████████████| 4.3MB 1.9MB/s
Collecting imageio>=2.3.0
Downloading https://files.pythonhosted.org/packages/1a/de/f7f985018f462ceeffada7f6e609919fbcc934acd9301929cba14bc2c24a/imageio-2.6.1-py3-none-any.whl (3.3MB)
|████████████████████████████████| 3.3MB 8.7MB/s
Collecting kiwisolver>=1.0.1
Downloading https://files.pythonhosted.org/packages/df/93/8bc9b52a8846be2b9572aa0a7c881930939b06e4abe1162da6a0430b794f/kiwisolver-1.1.0-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (113kB)
|████████████████████████████████| 122kB 1.9MB/s
Collecting python-dateutil>=2.1
Downloading https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
|████████████████████████████████| 235kB 7.1MB/s
Requirement already satisfied: numpy>=1.11 in /Users/aironman/.virtualenvs/cv/lib/python3.7/site-packages (from matplotlib!=3.0.0,>=2.0.0->scikit-image) (1.18.1)
Collecting cycler>=0.10
Downloading https://files.pythonhosted.org/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1
Downloading https://files.pythonhosted.org/packages/5d/bc/1e58593167fade7b544bfe9502a26dc860940a79ab306e651e7f13be68c2/pyparsing-2.4.6-py2.py3-none-any.whl (67kB)
|████████████████████████████████| 71kB 13.6MB/s
Collecting decorator>=4.3.0
Using cached https://files.pythonhosted.org/packages/8f/b7/f329cfdc75f3d28d12c65980e4469e2fa373f1953f5df6e370e84ea2e875/decorator-4.4.1-py2.py3-none-any.whl
Requirement already satisfied: setuptools in /Users/aironman/.virtualenvs/cv/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib!=3.0.0,>=2.0.0->scikit-image) (44.0.0)
Collecting six>=1.5
Using cached https://files.pythonhosted.org/packages/65/26/32b8464df2a97e6dd1b656ed26b2c194606c16fe163c695a992b36c11cdf/six-1.13.0-py2.py3-none-any.whl
Installing collected packages: kiwisolver, six, python-dateutil, cycler, pyparsing, matplotlib, pillow, decorator, networkx, scipy, PyWavelets, imageio, scikit-image
Successfully installed PyWavelets-1.1.1 cycler-0.10.0 decorator-4.4.1 imageio-2.6.1 kiwisolver-1.1.0 matplotlib-3.1.2 networkx-2.4 pillow-7.0.0 pyparsing-2.4.6 python-dateutil-2.8.1 scikit-image-0.16.2 scipy-1.4.1 six-1.13.0
(cv) bash-3.2$ pip install tree
Collecting tree
Downloading https://files.pythonhosted.org/packages/29/3f/63cbed2909786f0e5ac30a4ae5791ad597c6b5fec7167e161c55bba511ce/Tree-0.2.4.tar.gz
Requirement already satisfied: Pillow in /Users/aironman/.virtualenvs/cv/lib/python3.7/site-packages (from tree) (7.0.0)
Collecting svgwrite
Downloading https://files.pythonhosted.org/packages/4f/2e/f36cfec1da6162055b884e6366074cff18475a9538559ceae0c0bc58e186/svgwrite-1.3.1-py2.py3-none-any.whl (67kB)
|████████████████████████████████| 71kB 2.9MB/s
Requirement already satisfied: setuptools in /Users/aironman/.virtualenvs/cv/lib/python3.7/site-packages (from tree) (44.0.0)
Collecting click
Using cached https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl
Requirement already satisfied: pyparsing>=2.0.1 in /Users/aironman/.virtualenvs/cv/lib/python3.7/site-packages (from svgwrite->tree) (2.4.6)
Building wheels for collected packages: tree
Building wheel for tree (setup.py) … done
Created wheel for tree: filename=Tree-0.2.4-cp37-none-any.whl size=7879 sha256=6be33694eb4a910eaa8d2e360842698524ad9b21f4d92c23301ed00eb0135f60
Stored in directory: /Users/aironman/Library/Caches/pip/wheels/c7/08/aa/42261411808c634cd1d0e9fe6cde5e78bf47c2c8028f3930af
Successfully built tree
Installing collected packages: svgwrite, click, tree
Successfully installed click-7.0 svgwrite-1.3.1 tree-0.2.4
(cv) bash-3.2$ tree
bash: tree: command not found
(cv) bash-3.2$ python scan.py –image images/receipt.jpg
STEP 1: Edge Detection

STEP 2: Find contours of paper
STEP 3: Apply perspective transform
(cv) bash-3.2$
(cv) bash-3.2$ python scan.py –image images/
page.jpg receipt.jpg
(cv) bash-3.2$ python scan.py –image images/page.jpg
STEP 1: Edge Detection
STEP 2: Find contours of paper
STEP 3: Apply perspective transform
(cv) bash-3.2$ pwd
/Users/aironman/Downloads/document-scanner
(cv) bash-3.2$ pwd
/Users/aironman/Downloads/document-scanner
(cv) bash-3.2$ cd ..
(cv) bash-3.2$ cd
.DS_Store TDD – Yes we can.key
.localized TDD – Yes we can.pdf
81979757_525890651352521_5153718450325028864_o.jpg TelegramMac.dmg
Alonso Roman 2015002_010215.pdf UTM003_1.6.0_20191002_prod.dmg
Alonso Roman _010115.pdf Unigine_Heaven-4.0.dmg
Aloso Roman 2014004_011214.pdf Unigine_Heaven_Benchmark_4.0_20191104_1448.html
Archivo comprimido/ [limetorrents.info]SEAL.Team.S03E02.HDTV.x264-KILLERS[ettv].torrent
BE Skill Quiz.xlsx _hd_115314.jpg
Babylon 5/ ajax.html
BridgePattern/ cita-2.pdf
CV-MrAlonsoIsidoroRoman-updated-Oct-7-2019-EN.pdf cita-3.pdf
Captura de pantalla 2020-01-07 a las 20.39.13.png cita-4.pdf
Certif Ing y Retenc Netscout 2015 Isidoro.pdf cita-5.pdf
CinebenchR20.dmg cita.pdf
CorreosImpresoAdmision.pdf confluent-5.3.1/
Docker.dmg document-scanner/
Documento.pdf eclipse-inst-mac64.dmg
FA7C0CA7BAE35C1CFBDE690EE076DE08.pdf esercizio BE.pdf
FILENET_SRS003626544000_191125080008_28809_8588_W4_OL.PDF facturas emitidas/
Geekbench 5.app/ facturas emitidas-2/
Install Spotify.app/ files-WhatsApp.dmg
JUNE 2015 INVOICE ALONSO ROMAN.pdf ideaIC-2019.2.2.dmg
KeePassX-2.0.3.dmg justificante.pdf
Liquidacion Alonso Isidoro Roman-firmado.pdf mi-microservices-architecture-design-whitepaper-inc0336100lw-201602-a4-es.pdf
Liquidacion Alonso Isidoro Roman.pdf myActualKee-MidSept2019.kdbx
MISTRAL JosÇ Almazan and Maria del Carmen Gallego Spain/ opencv-4.0.0-0.jar
MacGameStore.dmg opencv-4.2.0/
Modelo de facturaSept2014.xls opencv-tutorial/
OnyX-2.dmg org.jboss.forge.plugin.idea/
OnyX.dmg output.txt
PinClipart.com_iron-man-logo-clipart_615853.png pizza_el-horno-de-crisol.jpeg
Python Crash Course – A Hands-On, Project-Based Introduction to Programming.pdf pycharm-community-2019.2.4.dmg
Roman Alonso’s details up to Sept 30 2015_Tektronix.pdf recordatorioCita.pdf
SEAL.Team.S03E02.HDTV.x264-KILLERS[ettv]/ russia-mission-on-mccain-funding-req.doc
SEAL.Team.S03E04.HDTV.x264-KILLERS[rarbg]/ steam.dmg
SEAL.Team.S03E05.WEB.h264-TBS[rarbg]/ ta.dms
Skype-8.55.0.141.dmg temperatura_co2.jpg
StarCraft-II-Setup.app/ test rumbo.pdf
Stremio+4.4.77.dmg tutorial-drools/
Sublime Text Build 3211.dmg w_java33.pdf
TDD – Yes we can-2.key
(cv) bash-3.2$ cd opencv-tutorial/
(cv) bash-3.2$ ls
jp.png opencv_tutorial_01.py opencv_tutorial_02.py tetris_blocks.png
(cv) bash-3.2$ cat opencv_tutorial_01.py
USAGE
python opencv_tutorial_01.py

import the necessary packages
import imutils
import cv2

load the input image and show its dimensions, keeping in mind that
images are represented as a multi-dimensional NumPy array with
shape no. rows (height) x no. columns (width) x no. channels (depth)
image = cv2.imread(“jp.png”)
(h, w, d) = image.shape
print(“width={}, height={}, depth={}”.format(w, h, d))

display the image to our screen — we will need to click the window
open by OpenCV and press a key on our keyboard to continue execution
cv2.imshow(“Image”, image)
cv2.waitKey(0)

access the RGB pixel located at x=50, y=100, keepind in mind that
OpenCV stores images in BGR order rather than RGB
(B, G, R) = image[100, 50]
print(“R={}, G={}, B={}”.format(R, G, B))

extract a 100×100 pixel square ROI (Region of Interest) from the
input image starting at x=320,y=60 at ending at x=420,y=160
roi = image[60:160, 320:420]
cv2.imshow(“ROI”, roi)
cv2.waitKey(0)

resize the image to 200x200px, ignoring aspect ratio
resized = cv2.resize(image, (200, 200))
cv2.imshow(“Fixed Resizing”, resized)
cv2.waitKey(0)

fixed resizing and distort aspect ratio so let’s resize the width
to be 300px but compute the new height based on the aspect ratio
r = 300.0 / w
dim = (300, int(h * r))
resized = cv2.resize(image, dim)
cv2.imshow(“Aspect Ratio Resize”, resized)
cv2.waitKey(0)

manually computing the aspect ratio can be a pain so let’s use the
imutils library instead
resized = imutils.resize(image, width=300)
cv2.imshow(“Imutils Resize”, resized)
cv2.waitKey(0)

let’s rotate an image 45 degrees clockwise using OpenCV by first
computing the image center, then constructing the rotation matrix,
and then finally applying the affine warp
center = (w // 2, h // 2)
M = cv2.getRotationMatrix2D(center, -45, 1.0)
rotated = cv2.warpAffine(image, M, (w, h))
cv2.imshow(“OpenCV Rotation”, rotated)
cv2.waitKey(0)

rotation can also be easily accomplished via imutils with less code
rotated = imutils.rotate(image, -45)
cv2.imshow(“Imutils Rotation”, rotated)
cv2.waitKey(0)

OpenCV doesn’t “care” if our rotated image is clipped after rotation
so we can instead use another imutils convenience function to help
us out
rotated = imutils.rotate_bound(image, 45)
cv2.imshow(“Imutils Bound Rotation”, rotated)
cv2.waitKey(0)

apply a Gaussian blur with a 11×11 kernel to the image to smooth it,
useful when reducing high frequency noise
blurred = cv2.GaussianBlur(image, (11, 11), 0)
cv2.imshow(“Blurred”, blurred)
cv2.waitKey(0)

draw a 2px thick red rectangle surrounding the face
output = image.copy()
cv2.rectangle(output, (320, 60), (420, 160), (0, 0, 255), 2)
cv2.imshow(“Rectangle”, output)
cv2.waitKey(0)

draw a blue 20px (filled in) circle on the image centered at
x=300,y=150
output = image.copy()
cv2.circle(output, (300, 150), 20, (255, 0, 0), -1)
cv2.imshow(“Circle”, output)
cv2.waitKey(0)

draw a 5px thick red line from x=60,y=20 to x=400,y=200
output = image.copy()
cv2.line(output, (60, 20), (400, 200), (0, 0, 255), 5)
cv2.imshow(“Line”, output)
cv2.waitKey(0)

draw green text on the image
output = image.copy()
cv2.putText(output, “OpenCV + Jurassic Park!!!”, (10, 25),
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
cv2.imshow(“Text”, output)
cv2.waitKey(0)(cv) bash-3.2$
(cv) bash-3.2$ python opencv_tutorial_01.py
width=600, height=322, depth=3
R=41, G=49, B=37
(cv) bash-3.2$ python opencv_tutorial_02.py
usage: opencv_tutorial_02.py [-h] -i IMAGE
opencv_tutorial_02.py: error: the following arguments are required: -i/–image
(cv) bash-3.2$ python opencv_tutorial_02.py -i
jp.png opencv_tutorial_01.py opencv_tutorial_02.py tetris_blocks.png
(cv) bash-3.2$ python opencv_tutorial_02.py -i jp.png
(cv) bash-3.2$ python opencv_tutorial_02.py -i tetris_blocks.png
(cv) bash-3.2$ pwd
/Users/aironman/Downloads/opencv-tutorial
(cv) bash-3.2$ ls
jp.png opencv_tutorial_01.py opencv_tutorial_02.py tetris_blocks.png
(cv) bash-3.2$ pwd
/Users/aironman/Downloads/opencv-tutorial
(cv) bash-3.2$ pwd
/Users/aironman/Downloads/opencv-tutorial
(cv) bash-3.2$

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s