OpenCV - Intersection between two binary images

前端 未结 2 1578
青春惊慌失措
青春惊慌失措 2021-02-01 20:57

Let\'s say I have two binary images of the same size. How do I find the intersection between the two binary images? Only pixels of the same coordinate (location) on the two imag

2条回答
  •  深忆病人
    2021-02-01 21:34

    Here's how to do this in python (with the images above):

    import cv2
    
    img1 = cv2.imread('black_top_right_triangle.png',0)
    img2 = cv2.imread('black_bottom_right_triangle.png',0)
    
    img_bwa = cv2.bitwise_and(img1,img2)
    img_bwo = cv2.bitwise_or(img1,img2)
    img_bwx = cv2.bitwise_xor(img1,img2)
    
    cv2.imshow("Bitwise AND of Image 1 and 2", img_bwa)
    cv2.imshow("Bitwise OR of Image 1 and 2", img_bwo)
    cv2.imshow("Bitwise XOR of Image 1 and 2", img_bwx)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

    If you need to install OpenCV for Python, save time by following these directions (installation has historically been quite a pain).

提交回复
热议问题