라즈베리

라즈베리 NOIR Camera V2

coding art 2018. 11. 25. 15:09
728x90

PiCamera v2를 설치하여 컬러 오브젝트 인식에 의한 자율주행 RC카 제작 진행과 더불어 부품 구매를 진행하다 보니 Raspberry Pi NOIR Camera 라는 제품이 있다는 것을 알게 되었다. 열화상 또는 적외선 카메라가 가격이 대단히 비싸다고 알고 있는데  NOIR 의 가격은 그냥 v2 와 거의 동일 가격하다. 자료를 보니 야간에 Night Vision 으로 사용도 가능하다는 얘기도 있는데 일단 한번 속는 셈치고 체크를 해봐야겠다는 생각이다.

라즈베리 보드에 설치 방법도 아무런 차이가 없으며 사용하는 방법도 PiCamera v2와 아무런 차이가 없는 듯하다. 다음의 비교사진은 블라인더를 친 실내 형광등 on 및 OFF 하에서 특성을 비교해 보았다. 사용한 코드는 color_BGR_detect.py 로서 색상 별로 hue 값 범위를 주어 색상별 마스크를 뜰 수 있는 코드이다. 실내 형광등 on 상태에서는 RGB 3가지 색상이 체크되었으나 형광등 OFF  조건하에서는 빨간색만이 주도적으로 체크 되었다.





별도로 어둠이 깔릴 때 스마트 폰 카메라로 잘 보이지 않을 정도일 때 NOIR이 어느 정도의  나이트비전(Night Vision) 능력을 보여 줄지 체크를 해 볼 필요가 있다. 나이트 비전 능력이 뛰어나다면 휴대용 카메라로 제작해 야간에 새나 박쥐 고양이 곤충 관찰이 가능할 지도 모르겠다.


#color_BGR_detect.py
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
import sys
import numpy as np


# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (320, 256)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(320, 256))

# allow the camera to warmup
time.sleep(0.1)

# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
 
    image = frame.array
    image = cv2.circle(image, (177,103), 32,(0,0,255), 3)
    image = cv2.rectangle(image, (0,0), (320,256),(255,255,255), 7)
    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    lower_red =   np.array([ 120,150,50])
    upper_red =   np.array([250,255,255])
    lower_blue =  np.array([90,150,50])
    upper_blue =  np.array([130,255,255])
    lower_green = np.array([50,150,50])
    upper_green = np.array([90,255,255])
    maskr = cv2.inRange(hsv, lower_red, upper_red)
    maskb = cv2.inRange(hsv, lower_blue, upper_blue)
    maskg = cv2.inRange(hsv, lower_green, upper_green)
    resr = cv2.bitwise_and(image,image, mask= maskr)
    resb = cv2.bitwise_and(image,image, mask= maskb)
    resg = cv2.bitwise_and(image,image, mask= maskg)
   
    cv2.imshow("image", image)
    cv2.imshow('maskr', maskr)
    cv2.imshow('maskb', maskb)
    cv2.imshow('maskg', maskg)
    cv2.imshow('resr',resr)
    cv2.imshow('resb',resb)              
    cv2.imshow('resg',resg)

   
    key = cv2.waitKey(1) & 0xFF
 # clear the stream in preparation for the next frame
    rawCapture.truncate(0)
 # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break