Created
October 11, 2015 15:07
-
-
Save michvaldes001/257853413eb733936847 to your computer and use it in GitHub Desktop.
This simple bit of code is for a project I'm working on. I intend to to simulate what it would look like if we has an extra cone in our eyes sensitive to near infrared light. This can be done by overlaying the feed of an IR camera over that of a normal camera. In reality we can't really conceive this new color. It would be akin to a colorblind p…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#must have OpenCV installed | |
import cv2 | |
#gets video feed from both cameras (this is for Linux) | |
cam = cv2.VideoCapture(0) | |
cam2 = cv2.VideoCapture(1) | |
#main loop | |
while True: | |
#process video feeds | |
im_value, img = cam.read() | |
im_value, img2 = cam2.read() | |
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY) | |
#increase contrast to highlight IR hotspots | |
img2 = cv2.equalizeHist(img2) | |
img2 = cv2.cvtColor(img2, cv2.COLOR_GRAY2BGR) | |
#removes green channel for magenta color | |
img2[:,:,1] = 0 | |
#overlays IR image | |
im_merge = cv2.addWeighted(img,0.7, img2,0.3, 0) | |
cv2.imshow('Press ESC to exit', im_merge) | |
#exit on ESC | |
if cv2.waitKey(1) == 27: | |
break | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment