Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to stack pictures with python+opencv

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to stack pictures in python+opencv". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to stack pictures in python+opencv.

The code is as follows:

# import cv2# import numpy as np## img = cv2.imread ('.. / images/full.jpg') # # img_hor = np.hstack (img,img) # img_ver = np.vstack ((img,img)) # # cv2.imshow ('Horizontal',img_hor) # cv2.imshow (' Vertical',img_ver) # # cv2.waitKey (0) import cv2import numpy as np def stackImages (scale) ImgArray): rows = len (imgArray) cols = len (imgArray [0]) rowsAvailable = isinstance (imgArray [0], list) width = imgArray [0] [0] .shape [1] height = imgArray [0] [0] .shape [0] if rowsAvailable: for x in range (0, rows): for y in range (0) Cols): if imgArray [x] [y] .shape [: 2] = imgArray [0] [0] .shape [: 2]: imgArray [x] [y] = cv2.resize (imgArray [x] [y], (0,0), None, scale, scale) else: imgArray [x] [y] = cv2.resize (imgArray [x] [y] (imgArray [0] [0] .shape [1], imgArray [0] [0] .shape [0]), None, scale, scale) if len (img array [x] [y] .shape) = 2: imgArray [x] [y] = cv2.cvtColor (imgArray [x] [y], cv2.COLOR_GRAY2BGR) imageBlank = np.zeros ((height, width, 3) Np.uint8) hor = [imageBlank] * rows hor_con = [imageBlank] * rows for x in range (0, rows): hor [x] = np.hstack (imgArray [x]) ver = np.vstack (hor) else: for x in range (0 Rows): if imgArray [x] .shape [: 2] = imgArray [0] .shape [: 2]: imgArray [x] = cv2.resize (imgArray [x], (0,0), None,scale, scale) else: imgArray [x] = cv2.resize (imgArray [x], (imgArray [0] .shape [1], imgArray [0] .shape [0]), None,scale Scale) if len (imgArray [x] .shape) = 2: imgArray [x] = cv2.cvtColor (imgArray [x], cv2.COLOR_GRAY2BGR) hor= np.hstack (imgArray) ver = hor return ver img = cv2.imread ('.. / images/lanbojini.jpg') imgGray = cv2.cvtColor (img,cv2.COLOR_BGR2GRAY) imgStack = stackImages (0.5, ([img,imgGray,img], [img,img,img])) # imgStack = stackImages ([img,imgGray,img], [img,img,img]) # imgHor = np.hstack ((img,img)) # imgVer = np.vstack ((img,img)) # # cv2.imshow ("Horizontal", imgHor) # cv2.imshow ("Vertical", imgVer) cv2.imshow ("ImageStack", imgStack) cv2.waitKey (0)

Effect:

Thank you for reading, the above is the content of "how to stack pictures in python+opencv". After the study of this article, I believe you have a deeper understanding of how to stack pictures in python+opencv, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report