Acquaintance OpenCV-Python - 001

The main use code comments to the preliminary study OpenCV-Python

1. Picture initial use (combined matplotlib)

 

 

CV2 Import 
from matplotlib Import pyplot AS PLT

#load AN in Grayscale Image Color
IMG = cv2.imread ( r'woman.jpg ' , 0) # 0 indicates cv2.IMREAD_GRAYSCALE. Another 1 represents cv2.IMREAD_COLOR, -1 represents cv2.IMREAD_UNCHANGED
plt.imshow (IMG , CMap = 'Gray' , interpolation = 'Bicubic')
plt.xticks ([]) , plt.yticks ([]) # remove axis
plt.show ()

(for the original left, right is after the above picture shows the code runs)

Artwork

 

 

2. Video initial use

CV2 Import 
CAP = cv2.VideoCapture ( 0) # using digital camera is turned on the first few
the fourcc = cv2.VideoWriter_fourcc (* 'XVID')
OUT = cv2.VideoWriter ( 'output.avi' , the fourcc , 20.0 , ( 640 , 480 )) # VideoWriter (const String & filename, int fourcc , Double FPS, Size frameSize, BOOL isColor = to true)
the while (cap.isOpened ()):
RET , Frame = cap.read ()
IF RET == True:
Frame = CV2 .flip (frame , 0) # the frame inversion
out.write (frame) # to each frame is written out in
cv2.imshow ( 'frame' , frame) display each frame #
     #ord () function is CHR () function (for 8-bit ASCII string) or unichr () function (for Unicode object) pairings, it a character (a string of length 1) as a parameter and returns the corresponding an ASCII value, or Unicode value
IF cv2.waitKey (. 1) &0xFF == the ord ( 'Q'):
BREAK
the else:
BREAK
# Remember to release exhausted after the fall 
cap.release ()
out.release ()
cv2.destroyAllWindows ()

 

Guess you like

Origin www.cnblogs.com/August2019/p/11668989.html