-1

Can someone help what is wrong in code. I need code compare 2 PCB images and show where is differences. I'm new in code. Result must be to show differences in the image. I have tried everything and did not find solution.


import cv2
import numpy as np
ref = cv2.imread('Reference/Reference.jpg')
ref_gray = cv2.cvtColor(ref, cv2.COLOR_BGR2GRAY)
cv2.imshow('ref1',ref)
img = cv2.imread('WithDefects/WithDefects.jpg')
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('ref2',img)
diff = np.abs(ref_gray-img_gray)
diff_blur= cv2.medianBlur(diff, 3,3)
defects = np.where(diff_blur>50,255,0)
cv2.imshow(np.where(diff_blur>50,255,0))
cv2.imshow(diff_blur)
img_with_defects = np.where(defects == 255, (0,0,255),img)
cv2.imshow(img_with_defects)
cv2.waitKey(0)
cv2.destroyAllWindows()

I get error : line 17, in cv2.imshow(np.where(diff_blur>50,255,0)) cv2.error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'imshow'

Overload resolution failed:

  • imshow() missing required argument 'mat' (pos 2)
  • imshow() missing required argument 'mat' (pos 2)
  • imshow() missing required argument 'mat' (pos 2)
  • `cv2.imshow(diff_blur)` expects two arguments and you provide only one (which is treated as the name of the window and not an image actually), the same applies for `cv2.imshow(img_with_defects)` – Gameplay Feb 13 '23 at 13:14

1 Answers1

0

In your code, you're passing the result of "np.where" directly to "cv2.imshow" without providing a window name.

Try to change it to this instead,

cv2.imshow("Defects", np.where(diff_blur>50,255,0))
AmeriNam20
  • 103
  • 6