Home Resources

Camera Basics 1 : Frame Grabbing From Camera to OLED

 

Overview: We are going to take a look at how easy it is to grab a frame from a c3038 CMOS camera Module (OV6630) and push it to the OLED’s GRAM for display.


What you would need:

Hardware


Software


Introduction
The first thing that comes to people’s mind when you talk about vision systems if you’re doing it on a PC level is how difficult and expensive the entire system CAN be. On an open platform embedded level, sure the cost is significantly lower than its PC counterpart but the difficulty and the amount of reading you have to do prior to setting up and grabbing a single frame from the camera is one of the biggest hindrances to those wanting to add a vision element to their project.

Should you happen to be one of those looking for a way to add vision into your projects; this tutorial will prove helpful in demonstrating just how easy it is to get started.

For full details on the hardware and software used in this tutorial, head over to the download page and grab a copy of the datasheets and reference materials.

Hardware Setup

Setting up the BCore100 & OLED Board

  • Follow the Hardware Setup as illustrated here.

 Setting up the BCore100 & the C3038 Camera Module

  • Follow the Hardware Setup as illustrated here.


Connect the power supply and the Serial Comm.Key (refer to this if you're not sure) and that’s all the hardware we will be using.

 

Software Setup

  1. Launch BCoreIDE
  2. Enter your COM number assigned to your Comm.key
  3. Create a New Project
  4. Save Project


Programming the BCore100 to control the OLED and Camera

Now that that’s done, let’s start. Since we’ll need to display the image from the camera to the OLED screen, we’ll have to initialise the OLED and the Camera.

Initializing the OLED and Camera


BC CodeCode:

Public Sub Main()

'Init the OLED with a black background
OLED.Init(Const.Colour.Black)
Cam.Init() 'Initialise the Camera
Cam.Speed(2)

End Sub


Note: CAM.Speed;  Speed values range from 2 to 8, with 2 being the fastest and 8 being the slowest.


Setting up a Frame Border


Next, we’ll declare 2 points to form a single pixel border around where we are going to draw the camera images to.  We do that by specifying the coordinates of both point structures, and then draw a rectangle using the 2 points. We then set the Camera’s drawing position to start drawing at coordinates (41, 1). The result? A really nice frame around the image being captured from the camera.


BC CodeCode:

DIM P1, P2 AS POINT
Public Sub Main()

OLED.Init(Const.COLOUR.BLACK)
'Change the orientation of the OLED to portrait
OLED.Orientation = 1
CAM.INIT() 'Init the Camera
CAM.Speed(2) 'Set the SPEED of the camera to 2

P1.X = 40
P1.Y = 0
P2.X = 201
P2.Y = 121
'DRAW A RECTANGLE AROUND THE CAPTURED IMAGE
OLED.Draw.Rectangle(P1,P2)
'Set the position to draw the captured image to screen
CAM.Position(41,1)

End Sub

Frame Grabbing
The following code constantly grabs a frame from camera and pushes it to the OLED screen.
 

 

BC CodeCode:

Do
'Grab image from Camera module and immediately draw it to the OLED Screen.
CAM.GrabFrame()
Loop

CAM.GRABFRAME() instructs the camera to grab a single frame of image and push it to the OLED screen. By placing the instruction in a Do..Loop structure, the camera is instructed to do a frame capture again and again.  (Speed is set to 2, so we’ll get about 17-18 frames per second)

By default, the camera is set by the BCoreOS to capture a frame size of 160x120. The sizing may not exactly be big, but it’s big enough for most applications. (From line tracking to skin detection to character recognition)
To get a full screen camera capture, we will need to put in an external SRAM, but we’ll get to that some other time.

The full code should look something like this;

BC  CodeCode:

DIM P1, P2 AS POINT
Public Sub Main()

OLED.Init(Const.Colour.Black)
'Change the orientation of the OLED to portrait
OLED.Orientation = Const.OLED.Portrait
CAM.Init() 'Init the Camera
CAM.Speed(2) 'Set the SPEED of the camera to 2

P1.X = 40
P1.Y = 0
P2.X = 201
P2.Y = 121

'Draw a Rectangle around the captured image
OLED.Draw.Rectangle(P1,P2)

'Set the position to draw the captured image to screen
CAM.Position(41,1)

Do
'Grab image from Camera module and immediately draw it to the OLED Screen.
CAM.GrabFrame()
Loop

End Sub

 

And that’s it for the first part!