Skip to content
This repository
tree: 6b40c7b224
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 157 lines (135 sloc) 3.955 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
#include "kovan/camera.h"
#include "kovan/camera.hpp"
#include "nyi.h"
#include <iostream>

class DeviceSingleton
{
public:
static Camera::Device *instance()
{
static Camera::Device s_device;
return &s_device;
}
};

int camera_open()
{
return DeviceSingleton::instance()->open() ? 1 : 0;
}

int camera_open_device(int number)
{
return DeviceSingleton::instance()->open(number) ? 1 : 0;
}

void set_camera_grab_count(int grabs)
{
DeviceSingleton::instance()->setGrabCount(grabs);
}

int get_camera_grab_count()
{
return DeviceSingleton::instance()->grabCount();
}

int camera_load_config(const char *name)
{
Config *config = Config::load(Camera::ConfigPath::path(name));
if(!config) return 0;
DeviceSingleton::instance()->setConfig(*config);
delete config;
return 1;
}

void set_camera_width(int width)
{
if(width <= 0) {
std::cout << "Camera width must be greater than 0." << std::endl;
return;
}
DeviceSingleton::instance()->setWidth(width);
}

void set_camera_height(int height)
{
if(height <= 0) {
std::cout << "Camera height must be greater than 0." << std::endl;
return;
}
DeviceSingleton::instance()->setHeight(height);
}

int camera_update()
{
return DeviceSingleton::instance()->update() ? 1 : 0;
}

pixel get_camera_pixel(point2 p)
{
nyi("get_camera_pixel");
}

int get_channel_count()
{
return DeviceSingleton::instance()->channels().size();
}

bool check_channel(int i)
{
const Camera::ChannelPtrVector &channels = DeviceSingleton::instance()->channels();
if(i < 0 || i >= channels.size()) {
std::cout << "Channel must be in the range 0 .. " << (channels.size() - 1) << std::endl;
return false;
}
return true;
}

bool check_channel_and_object(int i, int j)
{
const Camera::ChannelPtrVector &channels = DeviceSingleton::instance()->channels();
if(i < 0 || i >= channels.size()) {
if(channels.size() < 1) std::cout << "Active configuration doesn't have any channels.";
else std::cout << "Channel must be in the range 0 .. " << (channels.size() - 1);
std::cout << std::endl;
return false;
}
const Camera::ObjectVector *objs = channels[i]->objects();
if(j < 0 || j >= objs->size()) {
std::cout << "No such object " << j << std::endl;
return false;
}
return true;
}

int get_object_count(int channel)
{
if(!check_channel(channel)) return -1;
return DeviceSingleton::instance()->channels()[channel]->objects()->size();
}

double get_object_confidence(int channel, int object)
{
if(!check_channel_and_object(channel, object)) return 0.0;
const Camera::Object &o = (*DeviceSingleton::instance()->channels()[channel]->objects())[object];
return o.confidence();
}


const char *get_object_data(int channel, int object)
{
if(!check_channel_and_object(channel, object)) return 0;
const Camera::Object &o = (*DeviceSingleton::instance()->channels()[channel]->objects())[object];
return o.data();
}

int get_object_data_length(int channel, int object)
{
if(!check_channel_and_object(channel, object)) return 0;
const Camera::Object &o = (*DeviceSingleton::instance()->channels()[channel]->objects())[object];
return o.dataLength();
}

int get_object_area(int channel, int object)
{
if(!check_channel_and_object(channel, object)) return -1;
const Camera::Object &o = (*DeviceSingleton::instance()->channels()[channel]->objects())[object];
return o.boundingBox().area();
}

rectangle get_object_bbox(int channel, int object)
{
if(!check_channel_and_object(channel, object)) return create_rectangle(-1, -1, 0, 0);
const Camera::Object &o = (*DeviceSingleton::instance()->channels()[channel]->objects())[object];
return o.boundingBox().toCRectangle();
}

point2 get_object_centroid(int channel, int object)
{
if(!check_channel_and_object(channel, object)) return create_point2(-1, -1);
const Camera::Object &o = (*DeviceSingleton::instance()->channels()[channel]->objects())[object];
return o.centroid().toCPoint2();
}

void camera_close()
{
DeviceSingleton::instance()->close();
}
Something went wrong with that request. Please try again.