opencv_vs_matplotlib
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| opencv_vs_matplotlib [2022/09/23 01:11] – jhagstrand | opencv_vs_matplotlib [2023/01/12 11:39] (current) – removed jhagstrand | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== OpenCV vs matplotlib ====== | ||
| - | |||
| - | data format | ||
| - | - both matplotlib and opencv express the image as a numpy array | ||
| - | - you can always manipulate the array directly using matrix math | ||
| - | - or, both matplotlib and opencv provide methods to do sophisticated operations | ||
| - | - there is considerable overlap between the two systems | ||
| - | - you can probably do whatever you want with either system | ||
| - | - and you can mix and match both systems, so long as you know the differences | ||
| - | - in the way they handle the array | ||
| - | color model | ||
| - | |||
| - | - by default, matplotlib uses RGB, opencv uses BGR | ||
| - | |||
| - | alpha channel | ||
| - | - by default, array shape is (y,x,3) | ||
| - | - can be changed to (y,x,4), for RGBA or BGRA | ||
| - | - example: | ||
| - | - y,x,d = myarray.shape | ||
| - | - numpy.dstack(myarray, | ||
| - | - [[https:// | ||
| - | |||
| - | display | ||
| - | - by default, matplotlib produces a graph | ||
| - | - - with x,y,z axis, with tickmarks and scale | ||
| - | - - the graph is positioned with margins inside a resizeable window | ||
| - | - opencv gives a full-size image in a fixed-size window | ||
| - | |||
| - | animation | ||
| - | - both systems provide systems for animation and user-input handling | ||
| - | - matplotlib FuncAnimation allows for an incremental blit | ||
| - | - matplotlib allows you to change the data of objects already in the plot | ||
| - | - opencv requires you to rewrite the whole screen | ||
| - | |||
| - | user input | ||
| - | - both systems allow you to wait for a key press | ||
| - | - both systems provide an event-handler for keyboard and mouse events | ||
| - | |||
| - | tiling | ||
| - | - numpy hstack() and vstack() can be used to tile multiple images into one | ||
| - | - in addition, matplotlib uses the Figure-> | ||
| - | |||
| - | how to overlay transparent plot on top of a photo | ||
| - | |||
| - | 1. convert plot to image | ||
| - | google: convert matplotlib figure to numpy array opencv | ||
| - | https: | ||
| - | |||
| - | 2. overlay transparent plot on top of image | ||
| - | https: | ||
| - | |||
| - | in cv2, | ||
| - | use cv2.inRange() to make a mask | ||
| - | use cv2.bitwise_and() to make masked image | ||
| - | see ../ | ||
| - | |||
| - | in matplotlib, | ||
| - | use imshow() twice, where second, top, image has alpha channel\\ | ||
| - | https:// | ||
| - | ax.imshow(bottom, | ||
| - | ax.imshow(topimg, | ||
| - | |||
opencv_vs_matplotlib.1663909892.txt.gz · Last modified: 2022/09/23 01:11 by jhagstrand