CAMERA BASICS 1 : FRAME GRABBING FROM CAMERA TO OLED In this tutorial, we are going to take a look at how easy it is to grab a frame from a camera and push it to the OLED’s GRAM for displaying.
What you would need:
Hardware
- BlazingCore100
- 2.83” OLED w/ Touch Screen Interface Board
- Embedded CMOS Camera (C3038)
- Serial Comm.Key
- Power Supply (6V – 12V DC)
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 below by stacking the boards on each other with the OLED and BCore Board Facing outwards; and the back of both boards facing each other on the inside. TIP: Use the Pins parallel to the 4 JST connectors on the right to help align the two boards. 
Setting up the BCore100 & Camera Module  Connect the power supply and the Serial Comm.Key and that’s all the hardware we will be using. Software Setup
- Launch BCoreIDE
- Enter your COM number assigned to your Comm.key
- Create a New Project
- 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
Code:
Public Sub Main()
'Init the OLED with a black background OLED.Init(BCK.COLOUR.BLACK) CAM.INIT() 'Init the Camera CAM.WRITEREG(17,6) 'Set the SPEED of the camera to 6
End Sub
CAM.WRITEREG(register address, value) is a command that writes to the Camera’s Imaging Sensor Register, given the specified register address and the value in which to write into the register. In this case, the register address is 17 (0x11), which is the clock-rate control of OV6630; the value 6 is written to the clock rate control register, setting the speed of the camera to 6. Note: Speed values range from 1 to 8, with 1 being the fastest and 8 being the slowest. By default, the camera is initialised to speed 8. Speed 6 is recommended speed and anything less than 6 is not advisable.
TIP: For more info, please refer to OV6630 datasheet, as well as the BCore Vision System Documentation.
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.
Code:
DIM P1, P2 AS POINT Public Sub Main()
OLED.Init(BCK.COLOUR.BLACK) 'Change the orientation of the OLED to portrait OLED.Orientation = 1 CAM.INIT() 'Init the Camera CAM.WRITEREG(17,6) 'Set the SPEED of the camera to 6
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. Code:
DO 'GRAB THE IMAGE FORM THE CAMERA AND SEND IT TO THE OLED 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 6, so we’ll get about 10 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; Code:
DIM P1, P2 AS POINT Public Sub Main()
OLED.Init(BCK.COLOUR.BLACK) 'Change the orientation of the OLED to portrait OLED.Orientation = 1 CAM.INIT() 'Init the Camera CAM.WRITEREG(17,6) 'Set the SPEED of the camera to 6
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 THE IMAGE FORM THE CAMERA AND SEND IT TO THE OLED CAM.GRABFRAME() LOOP
End Sub
And that’s it for the first part! Try it out yourself! Tutorials and articles on the aforementioned applications mentioned in this tutorial will be posted up subsequently. Keep checking back!

|