learn the following †
- python introduction
- basic programs
- file IO/camera IO
- blur, morphology
- masking of simple color
python introduction †
- Indentation is very important in Python programming. Indentation level is used to determine the coding block (the grouping of statements) and scope of variables.
- Variable is accessible from same block or nested block. Variable doesn't need to declare before using. Type of variable is determined by value to be assigned. Variable declared "global" has globally scope.
- A comment starts with a hash character (#)
>python ./basic.py
0:0
1:1
2:3
3:6
4:10
5:15
6:21
7:28
8:36
9:45
sum is between 30 and 50
basic programs †
About color, file IO, blur, morphology, and masking of simple color †
- Digital color image is usually constructed with 3 color components, Red, Green, Blue. But, in case of object detection from image, it is not convenient to use RGB color component. Therefore, HSV components is often utilized (H means Hue. S means Saturation. V means Value (luminance)).
- In Python programming, you can import the image, separate color components, convert to HSV, with following very simple code by using OpenCV package.
- Line 154 to 162 (separate color components)
- Variable img is arrayed in a "height" x "width" x "the number of color channels" matrix. In the RGB image, color channels are arranged in order B, G, R.
- Execute the Sample01 program, and click any position on the target image, you can observe the HSV values in around area of clicked position.
web camera IO †
To capture video from cameras, we can use VideoCapture Class. It is included in the module “cv2: OpenCV 3.2.0”.
(cf. Getting Started with Videos @ OpenCV 3.2.0)
- Line 07 (capture a frame)
ret, frame = cap.read()
- “ret” is bool (If frame is read correctly, it will be ‘Ture’)
- “frame” is a image data (numpy.ndarray object)
- Line 06 (create a loop, and capture frame-by-frame)
while cap.isOpened():
- “cap.isOpened()” can check whether “cap (VideoCapture object)” is initialized or not
- If it is initialized, this loop becomes infinite loop
- We can add some image processing at line 08.
ex.
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # <- change color space (RGB2GRAY)
cv2.imshow(‘video frame’, gray) # <- display the gray image