In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is to share with you the content of an example analysis of the basic operation of OpenCV images. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Overview
OpenCV is a cross-platform computer vision library that supports multiple languages and has powerful functions.
Intercept image
Example:
# intercepted image img = cv2.imread ("picture.jpg") img = img [200 img 600, 400 picture.jpg 1000] cv2.imshow ("cut", img) cv2.waitKey (0) cv2.destroyAllWindows ()
Output result:
Get color channel
Cv2.split can help us get different color channels.
Format:
Cv2.split (img)
Example:
# get color channel img = cv2.imread ("picture.jpg") # read image b, g, r = cv2.split (img) # split color channel print (r.shape, g.shape, b.shape) # debug output
Output result:
(1263, 1920) (1263, 1920) (1263, 1920)
Single channel display
# single channel display img = cv2.imread ("picture.jpg") # read picture cur_img = img.copy () # Deep copy cur_img [:,:, 0] = 0 # B channel set to 0cur_img [:,:, 1] = 0 # G channel set to 0cv2.imshow ("B channel", cur_img) # picture display cv2.waitKey (0) cv2.destroyAllWindows ()
Output result:
Read video
Cv2.VideoCapture can help us read videos. Use numbers to control different devices, such as 0,1. Or specify the video file path.
Format:
Cv2.VideoCapture (video_path or device_index)
Parameters:
Video_path: video file path
Device_index: video recording device (camera) index, such as 0,1
Example:
# read video vc = cv2.VideoCapture ("video.mp4") # Loop while (True): # read a frame, ret is bool type, indicating whether to read this frame ret successfully, frame = vc.read () # convert grayscale image gray = cv2.cvtColor (frame, cv2.COLOR_BGR2GRAY) # display cv2.imshow ('frame', gray) # if you don't press Q key Then every 1 millisecond displays a frame if cv2.waitKey (1) & 0xFF = = ord ('q'): break# releases vc.release () cv2.destroyAllWindows () Thank you for reading! This is the end of the article on "sample Analysis of the basic Operation of OpenCV Images". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.