33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
import cv2
|
|
|
|
# %%
|
|
bkg_old = cv2.imread(
|
|
"/home/leonarski_f/aaredaq/daq/src/aaredaq/alc_test_images/bkg280_50_50_old.jpg"
|
|
)
|
|
bkg_new = cv2.imread("/home/leonarski_f/aaredaq/daq/src/aaredaq/alc_test_images/bkg280_50_50.jpg")
|
|
grey_old = cv2.cvtColor(bkg_old, cv2.COLOR_RGB2GRAY)
|
|
grey_new = cv2.cvtColor(bkg_new, cv2.COLOR_RGB2GRAY)
|
|
diff_image = cv2.absdiff(grey_old, grey_new)
|
|
_, thresh_diff = cv2.threshold(diff_image, 1, 255, cv2.THRESH_BINARY)
|
|
|
|
# Display the results
|
|
cv2.imshow("Original Image 1", bkg_old)
|
|
cv2.imshow("Original Image 2", bkg_new)
|
|
cv2.imshow("Grayscale 1", grey_old)
|
|
cv2.imshow("Grayscale 2", grey_new)
|
|
cv2.imshow("Difference Image", diff_image)
|
|
cv2.imshow("Thresholded Difference", thresh_diff)
|
|
|
|
# Save the difference image
|
|
cv2.imwrite(
|
|
"/home/leonarski_f/aaredaq/daq/src/aaredaq/alc_test_images/bkg_difference_image.jpg", diff_image
|
|
)
|
|
cv2.imwrite(
|
|
"/home/leonarski_f/aaredaq/daq/src/aaredaq/alc_test_images/bkg_thresholded_difference.jpg",
|
|
thresh_diff,
|
|
)
|
|
|
|
# Wait for a key press and close all windows
|
|
cv2.waitKey(0)
|
|
cv2.destroyAllWindows()
|