Skip to content

Instantly share code, notes, and snippets.

@JinhaiZ
Last active January 21, 2018 08:42
Show Gist options
  • Save JinhaiZ/0b5c740c365ebe3b77605922fe73d374 to your computer and use it in GitHub Desktop.
Save JinhaiZ/0b5c740c365ebe3b77605922fe73d374 to your computer and use it in GitHub Desktop.
basic image processing using OpenCV library for Python

Algo

Converting multiple BMPs to an AVI without compression

You can use the huffyuv encoder to create a lossless output:

ffmpeg -i img%d.jpg -vcodec huffyuv output.avi

or rawvideo:

ffmpeg -i img%d.jpg -vcodec rawvideo output.avi

By default this will assume your input frame rate is 25, so you can add an option to change it:

ffmpeg -r 30 -i img%d.jpg -vcodec huffyuv output.avi

By default the output will inherit the input frame rate. You can apply the same option to the output. By changing the frame rates you can achieve a certain duration. For example, if I have 900 images and want the output duration to be 60 seconds with an output frame rate of 30, then 900/60=15.

ffmpeg -r 15 -i img%d.jpg -r 30 -vcodec huffyuv output.avi

Note that your images must be named in a sequence starting with 1, and although some encoders are lossless there can be some loss due to colorspace conversion. See FFmpeg FAQ: How do I encode single pictures into movies? (http://ffmpeg.org/faq.html#SEC14) for more info.

credit : https://ubuntuforums.org/archive/index.php/t-1815998.html

update frame in matplotlib with live camera preview

credit: https://stackoverflow.com/questions/44598124/update-frame-in-matplotlib-with-live-camera-preview

Temporal median image of multiple images

credit: https://stackoverflow.com/questions/28682985/temporal-median-image-of-multiple-images

Most efficient way to map function over numpy array

credit: https://stackoverflow.com/questions/35215161/most-efficient-way-to-map-function-over-numpy-array

connected component labeling in python

credit: https://stackoverflow.com/questions/46441893/connected-component-labeling-in-python

How to remove small connected objects using OpenCV

credit: https://stackoverflow.com/questions/42798659/how-to-remove-small-connected-objects-using-opencv

Morphological Transformations

https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_morphological_ops/py_morphological_ops.html

Structural Analysis and Shape Descriptors

https://docs.opencv.org/3.0-beta/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#connectedcomponents

Linear Interpolation using numpy.interp

https://stackoverflow.com/questions/13166914/linear-interpolation-using-numpy-interp

Apply a function repeatedly over multiple axes

https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.apply_along_axis.html

How to create a 2D “rect” array (square block of 1's, else 0's) in numpy?

https://stackoverflow.com/questions/10159178/how-to-create-a-2d-rect-array-square-block-of-1s-else-0s-in-numpy

How to print the full NumPy array?

https://stackoverflow.com/questions/1987694/how-to-print-the-full-numpy-array

Creating a GIF animation from PNG files

https://unix.stackexchange.com/questions/24014/creating-a-gif-animation-from-png-files

Fuzzy Control Systems: The Tipping Problem

http://pythonhosted.org/scikit-fuzzy/auto_examples/plot_tipping_problem_newapi.html

Online curve fitting

https://mycurvefit.com/

Communication

Inter-process Communication

https://en.wikipedia.org/wiki/Inter-process_communication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment