libkipr  1.0.0
Camera

Functions

int camera_open ()
 
int camera_open_black ()
 
int camera_open_at_res (enum Resolution res)
 
int camera_open_device (int number, enum Resolution res)
 
int camera_open_device_model_at_res (int number, enum Model model, enum Resolution res)
 
int camera_load_config (const char *name)
 
int get_camera_width (void)
 
int get_camera_height (void)
 
int camera_update (void)
 
pixel get_camera_pixel (point2 p)
 
int get_channel_count (void)
 
int get_object_count (int channel)
 
const char * get_object_data (int channel, int object)
 
int get_object_data_length (int channel, int object)
 
double get_object_confidence (int channel, int object)
 
int get_object_area (int channel, int object)
 
rectangle get_object_bbox (int channel, int object)
 
point2 get_object_centroid (int channel, int object)
 
point2 get_object_center (int channel, int object)
 
void camera_close ()
 
void set_camera_config_base_path (const char *const path)
 
const unsigned char * get_camera_frame_row (unsigned row)
 
const unsigned char * get_camera_frame ()
 

Detailed Description

The functions here deal with the camera. Specifically, the functions here deal with object detection through the use of color.

Setup

To use the object detections, you'll first have to have a .conf file. On a wombat, you can go to settings, then channels, then add a configuration. Next, edit that configuration and add a new channel (for the color object detection, it should be HSV Blob Tracking). Finally, configure that channel, selecting the color that you want the camera to detect when detecting objects on that channel.

Example object detection

Assuming you have a configuration file "botball.conf" and you have a Channel 0 on that file configured to detect red pom poms, then the following code would print 'red' when a red pom is seen.

#include <kipr/wombat.h>
#include <stdio.h>
int main(){
camera_load_config("botball.conf");
// wait a little and update the camera
int i = 0;
for (i = 0; i < 10; i++){
msleep(10);
}
int red_object_seen = 0;
while (!red_object_seen){
// get the bounding box of the largest object in
// channel 0 (the red channel)
rectangle object_bounding_box = get_object_bbox(0, 0);
if (object_bounding_box.width * object_bounding_box.height != 0){
printf("red object seen!");
red_object_seen = 1;
}
// update the camera
msleep(10);
}
camera_close(); // cleanup the camera
return 0;
}
rectangle get_object_bbox(int channel, int object)
int camera_open()
int camera_update(void)
int camera_load_config(const char *name)
void camera_close()
A rectangle object.
Definition: geometry.h:36
int width
the width of the rectangle
Definition: geometry.h:39
int height
the height of the rectangle
Definition: geometry.h:40
void msleep(long msecs)

Function Documentation

◆ camera_close()

void camera_close ( )

Cleanup the current camera instance.

See also
camera_open
camera_open_at_res
camera_open_device

◆ camera_load_config()

int camera_load_config ( const char *  name)

Loads the config file specified by name. The system will look for the config in the base path.

Parameters
nameThe configuration to load. Configuration file names are case sensitive.
Note
Do NOT include the config file extension ".conf" in the name parameter.
Returns
1 on success, 0 on failure.
See also
set_camera_config_base_path

◆ camera_open()

int camera_open ( )

Opens the default system camera for use at LOW_RES (160x120).

Returns
1 on success, 0 on failure
See also
camera_open_at_res
camera_open_device
camera_close

◆ camera_open_at_res()

int camera_open_at_res ( enum Resolution  res)

Opens the default system camera for use at a given resolution.

Parameters
resThe resolution the camera should operate at. This can be:
  • LOW_RES (160x120)
  • MED_RES (320x240)
  • HIGH_RES (640x480)
  • TELLO_RES (1280x720)
Warning
Only LOW_RES is currently supported. The function will fail for other resolutions.
Returns
1 on success, 0 on failure
See also
camera_open
camera_open_device
camera_close

◆ camera_open_black()

int camera_open_black ( )

Opens the default system camera for use at LOW_RES (160x120). This will improve frame rates for the black Logitech camera

Returns
1 on success, 0 on failure
See also
camera_open_at_res
camera_open_device
camera_close

◆ camera_open_device()

int camera_open_device ( int  number,
enum Resolution  res 
)

Opens a camera for use.

Parameters
numberThe camera's id. 0 is the first camera, 1 is the second camera, etc.
resThe resolution the camera should operate at. This can be:
  • LOW_RES (160x120)
  • MED_RES (320x240)
  • HIGH_RES (640x480)
  • TELLO_RES (1280x720)
Warning
Only LOW_RES is currently supported. The function will fail for other resolutions.
Returns
1 on success, 0 on failure
See also
camera_open
camera_close

◆ camera_open_device_model_at_res()

int camera_open_device_model_at_res ( int  number,
enum Model  model,
enum Resolution  res 
)

Opens a camera for use.

Parameters
numberThe camera's id. 0 is the first camera, 1 is the second camera, etc.
resThe resolution the camera should operate at. This can be:
  • LOW_RES (160x120)
  • MED_RES (320x240)
  • HIGH_RES (640x480)
  • TELLO_RES (1280x720)
modelThe camera model
  • WHITE_2016 The white 2016 Botball camera
  • BLACK_2017 The black 2017 Botball camera
  • TELLO Tello drone camera
Warning
MED_RES is supported only for the BLACK_2017 camera and HIGH_RES is not supported
Returns
1 on success, 0 on failure
See also
camera_open
camera_close

◆ camera_update()

int camera_update ( void  )

Pulls a new image from the camera for processing.

Returns
1 on success, 0 on failure.

◆ get_camera_frame()

const unsigned char* get_camera_frame ( )

Retrieves the current camera frame as a BGR (BGR888) array. The returned pointer is invalid after camera_update() is called again.

Returns
the current BGR888 camera frame.

◆ get_camera_frame_row()

const unsigned char* get_camera_frame_row ( unsigned  row)

Retrieves the current camera frame row as a BGR (BGR888) array. The returned pointer is invalid after camera_update() is called again.

Returns
the current BGR888 camera frame row.

◆ get_camera_height()

int get_camera_height ( void  )

Gets the camera's y resolution.

Attention
This value might be different than the previously set y resolution. Never assume the y resolution.
Returns
The camera's y resolution, in pixels.

◆ get_camera_pixel()

pixel get_camera_pixel ( point2  p)

Gets the color of a pixel.

Parameters
pThe point at which the pixel lies.
Returns
The rgb value of the pixel located at point p.
Note
A (r, g, b) value of (-1, -1, -1) will be returned for points that are out of range.

◆ get_camera_width()

int get_camera_width ( void  )

Gets the camera's x resolution.

Attention
This value might be different than the previously set x resolution. Never assume the x resolution.
Returns
The camera's x resolution, in pixels.

◆ get_channel_count()

int get_channel_count ( void  )
Returns
Number of channels in the current configuration.
See also
get_object_count

◆ get_object_area()

int get_object_area ( int  channel,
int  object 
)
Returns
The object's bounding box area. -1 is returned if the channel or object doesn't exist.

◆ get_object_bbox()

rectangle get_object_bbox ( int  channel,
int  object 
)
Returns
The bounding box of the given object on the given channel.

◆ get_object_center()

point2 get_object_center ( int  channel,
int  object 
)
Returns
The (x, y) center of the given object on the given channel.

◆ get_object_centroid()

point2 get_object_centroid ( int  channel,
int  object 
)
Returns
The (x, y) centroid of the given object on the given channel.

◆ get_object_confidence()

double get_object_confidence ( int  channel,
int  object 
)
Returns
The confidence, between 0.0 and 1.0, that given object on the given channel is significant. If the channel or object doesn't exist, 0.0 is returned.

◆ get_object_count()

int get_object_count ( int  channel)
Parameters
channelThe channel to scan for objects.
Note
Objects are sorted by area, largest first.
Returns
Number of objects in the given channel, -1 if channel doesn't exist.
See also
get_channel_count

◆ get_object_data()

const char* get_object_data ( int  channel,
int  object 
)
Returns
The string data associated with a given object on a given channel. If there is no data associated, 0 is returned.
Note
This data is not guaranteed to be null terminated.
This string pointer will be invalid after a call to camera_update()
See also
get_object_data_length

◆ get_object_data_length()

int get_object_data_length ( int  channel,
int  object 
)
Returns
The length of the string data associated with a given object on a given channel. If there is no data associated, 0 is returned. If the channel or object is invalid, 0 is returned.
See also
get_object_data

◆ set_camera_config_base_path()

void set_camera_config_base_path ( const char *const  path)

Sets the path in which to look for camera configurations.

Parameters
paththe absolute directory path in which to look for camera configurations.