Doxygen tutorials: python final edits
This commit is contained in:
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
@@ -70,20 +70,18 @@ pts = np.array([[10,5],[20,30],[70,20],[50,10]], np.int32)
|
||||
pts = pts.reshape((-1,1,2))
|
||||
cv2.polylines(img,[pts],True,(0,255,255))
|
||||
@endcode
|
||||
**note**
|
||||
|
||||
If third argument is False, you will get a polylines joining all the points, not a closed shape.
|
||||
@note If third argument is False, you will get a polylines joining all the points, not a closed
|
||||
shape.
|
||||
|
||||
**note**
|
||||
|
||||
cv2.polylines() can be used to draw multiple lines. Just create a list of all the lines you want
|
||||
to draw and pass it to the function. All lines will be drawn individually. It is a much better and
|
||||
faster way to draw a group of lines than calling cv2.line() for each line.
|
||||
@note cv2.polylines() can be used to draw multiple lines. Just create a list of all the lines you
|
||||
want to draw and pass it to the function. All lines will be drawn individually. It is a much better
|
||||
and faster way to draw a group of lines than calling cv2.line() for each line.
|
||||
|
||||
### Adding Text to Images:
|
||||
|
||||
To put texts in images, you need specify following things.
|
||||
- Text data that you want to write
|
||||
- Text data that you want to write
|
||||
- Position coordinates of where you want put it (i.e. bottom-left corner where data starts).
|
||||
- Font type (Check **cv2.putText()** docs for supported fonts)
|
||||
- Font Scale (specifies the size of font)
|
||||
@@ -95,12 +93,13 @@ We will write **OpenCV** on our image in white color.
|
||||
font = cv2.FONT_HERSHEY_SIMPLEX
|
||||
cv2.putText(img,'OpenCV',(10,500), font, 4,(255,255,255),2,cv2.LINE_AA)
|
||||
@endcode
|
||||
|
||||
### Result
|
||||
|
||||
So it is time to see the final result of our drawing. As you studied in previous articles, display
|
||||
the image to see it.
|
||||
|
||||

|
||||

|
||||
|
||||
Additional Resources
|
||||
--------------------
|
||||
@@ -112,4 +111,3 @@ Exercises
|
||||
---------
|
||||
|
||||
-# Try to create the logo of OpenCV using drawing functions available in OpenCV.
|
||||
|
||||
|
@@ -90,7 +90,7 @@ Result
|
||||
----------
|
||||
So it is time to see the final result of our drawing. As you studied in previous articles, display the image to see it.
|
||||
|
||||
.. image:: images/drawing.jpg
|
||||
.. image:: images/drawing_result.jpg
|
||||
:alt: Drawing Functions in OpenCV
|
||||
:align: center
|
||||
|
||||
|
@@ -23,8 +23,9 @@ Second argument is a flag which specifies the way image should be read.
|
||||
- cv2.IMREAD_GRAYSCALE : Loads image in grayscale mode
|
||||
- cv2.IMREAD_UNCHANGED : Loads image as such including alpha channel
|
||||
|
||||
@note Instead of these three flags, you can simply pass integers 1, 0 or -1 respectively. See the
|
||||
code below:
|
||||
@note Instead of these three flags, you can simply pass integers 1, 0 or -1 respectively.
|
||||
|
||||
See the code below:
|
||||
@code{.py}
|
||||
import numpy as np
|
||||
import cv2
|
||||
@@ -32,6 +33,7 @@ import cv2
|
||||
# Load an color image in grayscale
|
||||
img = cv2.imread('messi5.jpg',0)
|
||||
@endcode
|
||||
|
||||
**warning**
|
||||
|
||||
Even if the image path is wrong, it won't throw any error, but print img will give you None
|
||||
@@ -58,15 +60,19 @@ the program continues. If **0** is passed, it waits indefinitely for a key strok
|
||||
set to detect specific key strokes like, if key a is pressed etc which we will discuss below.
|
||||
|
||||
@note Besides binding keyboard events this function also processes many other GUI events, so you
|
||||
MUST use it to actually display the image. **cv2.destroyAllWindows()** simply destroys all the
|
||||
windows we created. If you want to destroy any specific window, use the function
|
||||
**cv2.destroyWindow()** where you pass the exact window name as the argument.
|
||||
MUST use it to actually display the image.
|
||||
|
||||
**cv2.destroyAllWindows()** simply destroys all the windows we created. If you want to destroy any
|
||||
specific window, use the function **cv2.destroyWindow()** where you pass the exact window name as
|
||||
the argument.
|
||||
|
||||
@note There is a special case where you can already create a window and load image to it later. In
|
||||
that case, you can specify whether window is resizable or not. It is done with the function
|
||||
**cv2.namedWindow()**. By default, the flag is cv2.WINDOW_AUTOSIZE. But if you specify flag to be
|
||||
cv2.WINDOW_NORMAL, you can resize window. It will be helpful when image is too large in dimension
|
||||
and adding track bar to windows. See the code below:
|
||||
and adding track bar to windows.
|
||||
|
||||
See the code below:
|
||||
@code{.py}
|
||||
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
|
||||
cv2.imshow('image',img)
|
||||
@@ -100,6 +106,7 @@ elif k == ord('s'): # wait for 's' key to save and exit
|
||||
cv2.imwrite('messigray.png',img)
|
||||
cv2.destroyAllWindows()
|
||||
@endcode
|
||||
|
||||
**warning**
|
||||
|
||||
If you are using a 64-bit machine, you will have to modify k = cv2.waitKey(0) line as follows :
|
||||
@@ -126,9 +133,13 @@ A screen-shot of the window will look like this :
|
||||

|
||||
|
||||
@sa Plenty of plotting options are available in Matplotlib. Please refer to Matplotlib docs for more
|
||||
details. Some, we will see on the way. .. warning:: Color image loaded by OpenCV is in BGR mode. But
|
||||
Matplotlib displays in RGB mode. So color images will not be displayed correctly in Matplotlib if
|
||||
image is read with OpenCV. Please see the exercises for more details.
|
||||
details. Some, we will see on the way.
|
||||
|
||||
__warning__
|
||||
|
||||
Color image loaded by OpenCV is in BGR mode. But Matplotlib displays in RGB mode. So color images
|
||||
will not be displayed correctly in Matplotlib if image is read with OpenCV. Please see the exercises
|
||||
for more details.
|
||||
|
||||
Additional Resources
|
||||
--------------------
|
||||
@@ -140,4 +151,3 @@ Exercises
|
||||
|
||||
-# There is some problem when you try to load color image in OpenCV and display it in Matplotlib.
|
||||
Read [this discussion](http://stackoverflow.com/a/15074748/1134940) and understand it.
|
||||
|
||||
|
@@ -60,9 +60,7 @@ For example, I can check the frame width and height by cap.get(3) and cap.get(4)
|
||||
640x480 by default. But I want to modify it to 320x240. Just use ret = cap.set(3,320) and
|
||||
ret = cap.set(4,240).
|
||||
|
||||
**note**
|
||||
|
||||
If you are getting error, make sure camera is working fine using any other camera application
|
||||
@note If you are getting error, make sure camera is working fine using any other camera application
|
||||
(like Cheese in Linux).
|
||||
|
||||
Playing Video from file
|
||||
@@ -90,10 +88,9 @@ while(cap.isOpened()):
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
@endcode
|
||||
**note**
|
||||
|
||||
Make sure proper versions of ffmpeg or gstreamer is installed. Sometimes, it is a headache to work
|
||||
with Video Capture mostly due to wrong installation of ffmpeg/gstreamer.
|
||||
@note Make sure proper versions of ffmpeg or gstreamer is installed. Sometimes, it is a headache to
|
||||
work with Video Capture mostly due to wrong installation of ffmpeg/gstreamer.
|
||||
|
||||
Saving a Video
|
||||
--------------
|
||||
@@ -148,6 +145,7 @@ cap.release()
|
||||
out.release()
|
||||
cv2.destroyAllWindows()
|
||||
@endcode
|
||||
|
||||
Additional Resources
|
||||
--------------------
|
||||
|
||||
|
Reference in New Issue
Block a user