Following the prior blog post about the installation of OpenCV to Raspberry Pi, then I  tested the installation using USB camera and Pi camera with python code. After that, I will show you the block set I build for putting a camera and raspberry in this post. This block set will put in the top of the fridge.

 

Test USB Camera

For this preliminary step, I will use webcam camera HD Logicool C270 with resolution 1280x720 pixel. Then I use the sample code for live view camera as below,

import numpy as np
import cv2
cap = cv2.VideoCapture(0)
if cap.isOpened() == False:
    print('Connecting camera')
else:
    print('Start Live View')
    cv2.namedWindow('USB Camera');
    cap.set(cv2.CAP_PROP_FRAME_WIDTH,640)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT,480)
    while( cap.isOpened() ):
        ret,frame = cap.read()
        if ret==False:
            print('Grabbing camera fail')
            break 
        cv2.imshow('Live',frame)       
        key = cv2.waitKey(5)
        if key==255: key=-1 
        if key >= 0:
            break
    print('Closing the camera') 
cap.release()
cv2.destroyAllWindows()

quit()

 

and this is the screenshot of the desktop

Fig.1 Screenshot of Live View using C270 Webcam camera

 

 

Test Pi Camera

After installing Pi camera provided in the Challenge Kit I copy the code from https://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/  as below,

from picamera.array import PiRGBArray
from picamera import PiCamera
import cv2
import time
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))
time.sleep(0.1)
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
     img = frame.array
     cv2.imshow("Live View", img)
     key = cv2.waitKey(1) & 0xFF
     rawCapture.truncate(0)
     if key == ord("q"):
          break

 

and the screenshot of the camera live view is shown below,

Fig.2 Screenshot of Live View using Pi Camera

 

 

Building Block set

The next step is building a block set for installed both webcam camera and raspberry. This block set will put in the top of the fridge for registering and recording the stock.

 

 

Closing Remarks

We have described our progress in this project. We have installed the openCV to Raspberry and test it using both USB camera and Pi Camera. We also build a block set for installing both camera and raspberry (Main server). The next step in our project plan is installed the Whatsapp messenger to raspberry for communication base. After that our plan is developing the blobing algorithm before recognition step. Hope that our project runs well.