diff --git a/Basics/Joining_Multiple_Images_To_Display.py b/Basics/Joining_Multiple_Images_To_Display.py index 694a1bc..f28040a 100644 --- a/Basics/Joining_Multiple_Images_To_Display.py +++ b/Basics/Joining_Multiple_Images_To_Display.py @@ -9,8 +9,9 @@ cap.set(3, frameWidth) cap.set(4, frameHeight) -def stackImages(imgArray,scale,lables=[]): - sizeW= imgArray[0][0].shape[1] + +def stackImages(imgArray, scale, lables=[]): + sizeW = imgArray[0][0].shape[1] sizeH = imgArray[0][0].shape[0] rows = len(imgArray) cols = len(imgArray[0]) @@ -18,13 +19,16 @@ def stackImages(imgArray,scale,lables=[]): width = imgArray[0][0].shape[1] height = imgArray[0][0].shape[0] if rowsAvailable: - for x in range ( 0, rows): + for x in range(0, rows): for y in range(0, cols): - imgArray[x][y] = cv2.resize(imgArray[x][y], (sizeW, sizeH), None, scale, scale) - if len(imgArray[x][y].shape) == 2: imgArray[x][y]= cv2.cvtColor( imgArray[x][y], cv2.COLOR_GRAY2BGR) + imgArray[x][y] = cv2.resize( + imgArray[x][y], (sizeW, sizeH), None, scale, scale + ) + if len(imgArray[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 + hor = [imageBlank] * rows + hor_con = [imageBlank] * rows for x in range(0, rows): hor[x] = np.hstack(imgArray[x]) hor_con[x] = np.concatenate(imgArray[x]) @@ -33,37 +37,57 @@ def stackImages(imgArray,scale,lables=[]): else: for x in range(0, rows): imgArray[x] = cv2.resize(imgArray[x], (sizeW, sizeH), None, scale, scale) - if len(imgArray[x].shape) == 2: imgArray[x] = cv2.cvtColor(imgArray[x], cv2.COLOR_GRAY2BGR) - hor= np.hstack(imgArray) - hor_con= np.concatenate(imgArray) + if len(imgArray[x].shape) == 2: + imgArray[x] = cv2.cvtColor(imgArray[x], cv2.COLOR_GRAY2BGR) + hor = np.hstack(imgArray) + hor_con = np.concatenate(imgArray) ver = hor if len(lables) != 0: - eachImgWidth= int(ver.shape[1] / cols) + eachImgWidth = int(ver.shape[1] / cols) eachImgHeight = int(ver.shape[0] / rows) print(eachImgHeight) for d in range(0, rows): - for c in range (0,cols): - cv2.rectangle(ver,(c*eachImgWidth,eachImgHeight*d),(c*eachImgWidth+len(lables[d][c])*13+27,30+eachImgHeight*d),(255,255,255),cv2.FILLED) - cv2.putText(ver,lables[d][c],(eachImgWidth*c+10,eachImgHeight*d+20),cv2.FONT_HERSHEY_COMPLEX,0.7,(255,0,255),2) + for c in range(0, cols): + cv2.rectangle( + ver, + (c * eachImgWidth, eachImgHeight * d), + ( + c * eachImgWidth + len(lables[d][c]) * 13 + 27, + 30 + eachImgHeight * d, + ), + (255, 255, 255), + cv2.FILLED, + ) + cv2.putText( + ver, + lables[d][c], + (eachImgWidth * c + 10, eachImgHeight * d + 20), + cv2.FONT_HERSHEY_COMPLEX, + 0.7, + (255, 0, 255), + 2, + ) return ver + while True: success, img = cap.read() - kernel = np.ones((5,5),np.uint8) + kernel = np.ones((5, 5), np.uint8) print(kernel) - #path = "Resources/lena.png" - #img = cv2.imread(path) - imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) - imgBlur = cv2.GaussianBlur(imgGray,(7,7),0) - imgCanny = cv2.Canny(imgBlur,100,200) - imgDilation = cv2.dilate(imgCanny,kernel , iterations = 2) - imgEroded = cv2.erode(imgDilation,kernel,iterations=2) + # path = "Resources/lena.png" + # img = cv2.imread(path) + imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + imgBlur = cv2.GaussianBlur(imgGray, (7, 7), 0) + imgCanny = cv2.Canny(imgBlur, 100, 200) + imgDilation = cv2.dilate(imgCanny, kernel, iterations=2) + imgEroded = cv2.erode(imgDilation, kernel, iterations=2) - #imgBlank = np.zeros((200,200),np.uint8) - StackedImages = stackImages(([img,imgGray,imgBlur], - [imgCanny,imgDilation,imgEroded]),0.6) + # imgBlank = np.zeros((200,200),np.uint8) + StackedImages = stackImages( + ([img, imgGray, imgBlur], [imgCanny, imgDilation, imgEroded]), 0.6 + ) cv2.imshow("Staked Images", StackedImages) - if cv2.waitKey(1) & 0xFF == ord('q'): + if cv2.waitKey(1) & 0xFF == ord("q"): break