图像混合:透明黑色区域
我正在尝试将棋盘添加到图像中,以找到失真系数。但是,当我使用函数addWeighted()
我的棋盘黑色区域是透明的。
首先,我将棋盘图像与功能findHomography()
和warpperspective()
然后,我尝试添加场景的图像和翘曲的棋盘与addWeighted()
一起。为了使其不透明,我需要做什么?
编辑代码:
input_1 = cv2.imread('RV_CV_Assignment_3_image_1.jpg')
imageSize = input_1.shape[:2]
chessboard = cv2.imread('Chessboard.jpg')
boardSize = np.float32([[0,0],[3632,0],[0,2816],[3632,2816]])
# These are the corner coordinates for the chessboard in the image. For now I do this manually
cornersBoard1 = np.float32([[348,233],[2004,233],[291,1555],[2025,1555]])
homography1, status1 = cv2.findHomography(boardSize,cornersBoard1)
warpBoard1 = cv2.warpPerspective(chessboard, homography1, (imageSize[1], imageSize[0]))
imgChessboard1 = cv2.addWeighted(input_1, 1, warpBoard1, 1, 0)
cv2.namedWindow('Chessboard in image 1', cv2.WINDOW_NORMAL)
cv2.imshow('Chessboard in image 1',imgChessboard1)
I'm trying to add a chessboard to an image in order to find the distortion coefficients. However when I use the function addWeighted()
the black areas of my chessboard are transparant.
First I warp my chessboard image with the functions findHomography()
and warpPerspective()
Then I try to add the image of the scene and the warped chessboard together with addWeighted()
. What do I need to do in order to get it not transparant?
Edit code:
input_1 = cv2.imread('RV_CV_Assignment_3_image_1.jpg')
imageSize = input_1.shape[:2]
chessboard = cv2.imread('Chessboard.jpg')
boardSize = np.float32([[0,0],[3632,0],[0,2816],[3632,2816]])
# These are the corner coordinates for the chessboard in the image. For now I do this manually
cornersBoard1 = np.float32([[348,233],[2004,233],[291,1555],[2025,1555]])
homography1, status1 = cv2.findHomography(boardSize,cornersBoard1)
warpBoard1 = cv2.warpPerspective(chessboard, homography1, (imageSize[1], imageSize[0]))
imgChessboard1 = cv2.addWeighted(input_1, 1, warpBoard1, 1, 0)
cv2.namedWindow('Chessboard in image 1', cv2.WINDOW_NORMAL)
cv2.imshow('Chessboard in image 1',imgChessboard1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是在Python/OpenCV中做到这一点的一种方法。确保您的“棋盘”图像将黑色映射到1而不是0。然后,在您的透视图上,请确保非图像背景颜色为纯黑色,即0。然后使用NP.使用NP。在其中融合了两个图像。
这是相应修改的代码,
结果:
Here is one way to do that in Python/OpenCV. Make sure your "chessboard" image has black mapped to 1 rather than 0. Then in your perspective warp, be sure the non-image background is colored as pure black, i.e. 0. Then use np.where to blend the two images.
Here is your code modified accordingly,
Result: