Factoring out camera_params.proto.
Change-Id: Idf886f9cb33764d505d5cff11ca766cea96d2024
diff --git a/aos/vision/debug/camera-source.cc b/aos/vision/debug/camera-source.cc
index ef48a11..77bd6ed 100644
--- a/aos/vision/debug/camera-source.cc
+++ b/aos/vision/debug/camera-source.cc
@@ -4,6 +4,7 @@
#include <fstream>
#include <string>
+#include "aos/vision/image/camera_params.pb.h"
#include "aos/vision/image/image_stream.h"
namespace aos {
@@ -15,26 +16,20 @@
DebugFrameworkInterface *interface) override {
// TODO: Get these params from a config file passed in through the
// constructor.
- camera::CameraParams params = {.width = 640 * 2,
- .height = 480 * 2,
- .exposure = 10,
- .brightness = 128,
- .gain = 0,
- .fps = 30};
- image_stream_.reset(new ImageStream(jpeg_list_filename, params, interface));
+ image_stream_.reset(new ImageStream(
+ jpeg_list_filename, aos::vision::CameraParams(), interface));
}
const char *GetHelpMessage() override {
return &R"(
format_spec is filename of the camera device.
example: camera:/dev/video0
- This viewer source will stream video from a usb camera of your choice.
-)"[1];
+ This viewer source will stream video from a usb camera of your choice.)"[1];
}
class ImageStream : public ImageStreamEvent {
public:
- ImageStream(const std::string &fname, camera::CameraParams params,
+ ImageStream(const std::string &fname, aos::vision::CameraParams params,
DebugFrameworkInterface *interface)
: ImageStreamEvent(fname, params), interface_(interface) {
interface_->Loop()->Add(this);
diff --git a/aos/vision/image/BUILD b/aos/vision/image/BUILD
index 662addc..27646a5 100644
--- a/aos/vision/image/BUILD
+++ b/aos/vision/image/BUILD
@@ -1,4 +1,5 @@
package(default_visibility = ['//visibility:public'])
+load('/tools/build_rules/protobuf', 'proto_cc_library')
cc_library(
name = 'image_types',
@@ -8,6 +9,11 @@
],
)
+proto_cc_library(
+ name = 'camera_params',
+ src = 'camera_params.proto',
+)
+
cc_library(
name = 'reader',
srcs = ['reader.cc'],
@@ -16,6 +22,7 @@
'//aos/common:time',
'//aos/common/logging:logging',
':image_types',
+ ':camera_params',
],
)
diff --git a/aos/vision/image/camera_params.proto b/aos/vision/image/camera_params.proto
new file mode 100644
index 0000000..c109154
--- /dev/null
+++ b/aos/vision/image/camera_params.proto
@@ -0,0 +1,23 @@
+syntax = "proto2";
+
+package aos.vision;
+
+message CameraParams {
+ // Width of the image.
+ optional int32 width = 1 [default = 1280];
+
+ // Height of the image.
+ optional int32 height = 2 [default = 960];
+
+ // Exposure setting.
+ optional int32 exposure = 3 [default = 10];
+
+ // Brightness setting.
+ optional int32 brightness = 4 [default = 128];
+
+ // Hardware gain multiplier on pixel values.
+ optional int32 gain = 5 [default = 0];
+
+ // Frames per second to run camera.
+ optional int32 fps = 6 [default = 30];
+}
diff --git a/aos/vision/image/image_stream.h b/aos/vision/image/image_stream.h
index 5a1ad21..308d3ec 100644
--- a/aos/vision/image/image_stream.h
+++ b/aos/vision/image/image_stream.h
@@ -2,6 +2,7 @@
#define _AOS_VISION_IMAGE_IMAGE_STREAM_H_
#include "aos/vision/events/epoll_events.h"
+#include "aos/vision/image/camera_params.pb.h"
#include "aos/vision/image/reader.h"
#include <memory>
@@ -15,7 +16,7 @@
public:
static std::unique_ptr<::camera::Reader> GetCamera(
const std::string &fname, ImageStreamEvent *obj,
- camera::CameraParams params) {
+ aos::vision::CameraParams params) {
using namespace std::placeholders;
std::unique_ptr<::camera::Reader> camread(new ::camera::Reader(
fname, std::bind(&ImageStreamEvent::ProcessHelper, obj, _1, _2),
@@ -28,7 +29,7 @@
: ::aos::events::EpollEvent(reader->fd()), reader_(std::move(reader)) {}
explicit ImageStreamEvent(const std::string &fname,
- camera::CameraParams params)
+ aos::vision::CameraParams params)
: ImageStreamEvent(GetCamera(fname, this, params)) {}
void ProcessHelper(DataRef data, aos::monotonic_clock::time_point timestamp) {
diff --git a/aos/vision/image/reader.cc b/aos/vision/image/reader.cc
index 03e2fc8..57766e2 100644
--- a/aos/vision/image/reader.cc
+++ b/aos/vision/image/reader.cc
@@ -1,7 +1,19 @@
-#include "aos/common/time.h"
+#include "aos/vision/image/reader.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <malloc.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
#include "aos/common/logging/logging.h"
-#include "aos/vision/image/reader.h"
+#include "aos/common/time.h"
#define CLEAR(x) memset(&(x), 0, sizeof(x))
@@ -12,8 +24,21 @@
size_t length; // for munmap
};
+aos::vision::CameraParams MakeCameraParams(int32_t width, int32_t height,
+ int32_t exposure, int32_t brightness,
+ int32_t gain, int32_t fps) {
+ aos::vision::CameraParams cam;
+ cam.set_width(width);
+ cam.set_height(height);
+ cam.set_exposure(exposure);
+ cam.set_brightness(brightness);
+ cam.set_gain(gain);
+ cam.set_fps(fps);
+ return cam;
+}
+
Reader::Reader(const std::string &dev_name, ProcessCb process,
- CameraParams params)
+ aos::vision::CameraParams params)
: dev_name_(dev_name), process_(std::move(process)), params_(params) {
struct stat st;
if (stat(dev_name.c_str(), &st) == -1) {
@@ -67,7 +92,7 @@
}
if (!SetCameraControl(V4L2_CID_EXPOSURE_ABSOLUTE,
- "V4L2_CID_EXPOSURE_ABSOLUTE", params_.exposure)) {
+ "V4L2_CID_EXPOSURE_ABSOLUTE", params_.exposure())) {
LOG(FATAL, "Failed to set exposure\n");
}
}
@@ -200,8 +225,8 @@
v4l2_format fmt;
CLEAR(fmt);
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
- fmt.fmt.pix.width = params_.width;
- fmt.fmt.pix.height = params_.height;
+ fmt.fmt.pix.width = params_.width();
+ fmt.fmt.pix.height = params_.height();
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
fmt.fmt.pix.field = V4L2_FIELD_ANY;
// fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
@@ -224,16 +249,16 @@
}
if (!SetCameraControl(V4L2_CID_EXPOSURE_ABSOLUTE,
- "V4L2_CID_EXPOSURE_ABSOLUTE", params_.exposure)) {
+ "V4L2_CID_EXPOSURE_ABSOLUTE", params_.exposure())) {
LOG(FATAL, "Failed to set exposure\n");
}
if (!SetCameraControl(V4L2_CID_BRIGHTNESS, "V4L2_CID_BRIGHTNESS",
- params_.brightness)) {
+ params_.brightness())) {
LOG(FATAL, "Failed to set up camera\n");
}
- if (!SetCameraControl(V4L2_CID_GAIN, "V4L2_CID_GAIN", params_.gain)) {
+ if (!SetCameraControl(V4L2_CID_GAIN, "V4L2_CID_GAIN", params_.gain())) {
LOG(FATAL, "Failed to set up camera\n");
}
@@ -243,7 +268,7 @@
memset(setfps, 0, sizeof(struct v4l2_streamparm));
setfps->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
setfps->parm.capture.timeperframe.numerator = 1;
- setfps->parm.capture.timeperframe.denominator = params_.fps;
+ setfps->parm.capture.timeperframe.denominator = params_.fps();
if (xioctl(fd_, VIDIOC_S_PARM, setfps) == -1) {
PLOG(FATAL, "ioctl VIDIOC_S_PARM(%d, %p)\n", fd_, setfps);
}
diff --git a/aos/vision/image/reader.h b/aos/vision/image/reader.h
index 28735fb..e913ad1 100644
--- a/aos/vision/image/reader.h
+++ b/aos/vision/image/reader.h
@@ -1,16 +1,5 @@
#ifndef AOS_VISION_IMAGE_READER_H_
#define AOS_VISION_IMAGE_READER_H_
-#include <errno.h>
-#include <fcntl.h>
-#include <malloc.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
#include <inttypes.h>
#include <functional>
@@ -18,24 +7,21 @@
#include "aos/common/time.h"
#include "aos/vision/image/V4L2.h"
+#include "aos/vision/image/camera_params.pb.h"
#include "aos/vision/image/image_types.h"
namespace camera {
-struct CameraParams {
- int32_t width;
- int32_t height;
- int32_t exposure;
- int32_t brightness;
- int32_t gain;
- int32_t fps;
-};
+aos::vision::CameraParams MakeCameraParams(int32_t width, int32_t height,
+ int32_t exposure, int32_t brightness,
+ int32_t gain, int32_t fps);
class Reader {
public:
using ProcessCb = std::function<void(
aos::vision::DataRef data, aos::monotonic_clock::time_point timestamp)>;
- Reader(const std::string &dev_name, ProcessCb process, CameraParams params);
+ Reader(const std::string &dev_name, ProcessCb process,
+ aos::vision::CameraParams params);
aos::vision::ImageFormat get_format();
@@ -74,7 +60,7 @@
static const unsigned int kNumBuffers = 5;
// set only at initialize
- CameraParams params_;
+ aos::vision::CameraParams params_;
};
} // namespace camera
diff --git a/aos/vision/tools/camera_primer.cc b/aos/vision/tools/camera_primer.cc
index a431ac8..3ba24bc 100644
--- a/aos/vision/tools/camera_primer.cc
+++ b/aos/vision/tools/camera_primer.cc
@@ -5,7 +5,7 @@
class ImageStream : public aos::vision::ImageStreamEvent {
public:
- ImageStream(const std::string &fname, camera::CameraParams params)
+ ImageStream(const std::string &fname, aos::vision::CameraParams params)
: ImageStreamEvent(fname, params) {}
void ProcessImage(aos::vision::DataRef /*data*/,
aos::monotonic_clock::time_point) override {
@@ -30,12 +30,7 @@
::aos::logging::AddImplementation(
new ::aos::logging::StreamLogImplementation(stdout));
- camera::CameraParams params = {.width = 640 * 2,
- .height = 480 * 2,
- .exposure = 10,
- .brightness = 128,
- .gain = 0,
- .fps = 30};
+ aos::vision::CameraParams params;
if (argc != 2) {
fprintf(stderr, "usage: %s path_to_camera\n", argv[0]);
diff --git a/aos/vision/tools/jpeg_vision_test.cc b/aos/vision/tools/jpeg_vision_test.cc
index 52dd22f..059166e 100644
--- a/aos/vision/tools/jpeg_vision_test.cc
+++ b/aos/vision/tools/jpeg_vision_test.cc
@@ -42,7 +42,7 @@
class ChannelImageStream : public ImageStreamEvent {
public:
ChannelImageStream(const std::string &fname,
- const camera::CameraParams ¶ms)
+ const aos::vision::CameraParams ¶ms)
: ImageStreamEvent(fname, params), view_(false) {
// Lambda to record image data to a file on key press.
view_.view()->key_press_event = [this](uint32_t keyval) {
@@ -117,12 +117,7 @@
aos::events::EpollLoop loop;
gtk_init(&argc, &argv);
- camera::CameraParams params = {.width = 640 * 2,
- .height = 480 * 2,
- .exposure = 10,
- .brightness = 128,
- .gain = 0,
- .fps = 25};
+ aos::vision::CameraParams params;
aos::vision::ChannelImageStream strm1("/dev/video1", params);
diff --git a/tools/build_rules/protobuf.bzl b/tools/build_rules/protobuf.bzl
index c9bb9ef..f6a98b8 100644
--- a/tools/build_rules/protobuf.bzl
+++ b/tools/build_rules/protobuf.bzl
@@ -72,7 +72,7 @@
name = '%s__proto_srcs' % name,
srcs = [src],
deps = [('%s__proto_srcs' % o_name) for o_name in deps],
- visibility = ['//visibility:private'],
+ visibility = visibility,
)
basename = src[:-len('.proto')]
native.cc_library(
diff --git a/y2016/vision/BUILD b/y2016/vision/BUILD
index e8d0b17..d8ca87c 100644
--- a/y2016/vision/BUILD
+++ b/y2016/vision/BUILD
@@ -143,7 +143,7 @@
"//aos/vision/events:tcp_client",
"//aos/vision/events:epoll_events",
"//aos/vision/events:gtk_event",
- "//aos/vision/debug:debug_viewer",
+ "//aos/vision/debug:debug_window",
"//aos/vision/blob:range_image",
"//aos/vision/blob:codec",
"//aos/vision/blob:stream_view",
diff --git a/y2016/vision/debug_receiver.cc b/y2016/vision/debug_receiver.cc
index 7039c53..d3c527c 100644
--- a/y2016/vision/debug_receiver.cc
+++ b/y2016/vision/debug_receiver.cc
@@ -12,7 +12,6 @@
#include "aos/vision/events/socket_types.h"
#include "aos/vision/events/tcp_client.h"
#include "aos/vision/events/epoll_events.h"
-#include "aos/vision/debug/debug_viewer.h"
#include "aos/vision/blob/range_image.h"
#include "aos/vision/blob/codec.h"
#include "aos/vision/blob/stream_view.h"
@@ -69,9 +68,9 @@
private:
void DrawCross(PixelLinesOverlay &overlay, Vector<2> center, PixelRef color) {
- overlay.add_line(Vector<2>(center.x() - 50, center.y()),
+ overlay.AddLine(Vector<2>(center.x() - 50, center.y()),
Vector<2>(center.x() + 50, center.y()), color);
- overlay.add_line(Vector<2>(center.x(), center.y() - 50),
+ overlay.AddLine(Vector<2>(center.x(), center.y() - 50),
Vector<2>(center.x(), center.y() + 50), color);
}
diff --git a/y2016/vision/target_sender.cc b/y2016/vision/target_sender.cc
index 2790a83..85e62c4 100644
--- a/y2016/vision/target_sender.cc
+++ b/y2016/vision/target_sender.cc
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <sys/stat.h>
#include <fstream>
#include <iostream>
#include <memory>
@@ -37,13 +38,15 @@
using aos::events::DataSocket;
using aos::vision::ImageFormat;
-::camera::CameraParams GetCameraParams(const Calibration &calibration) {
- return ::camera::CameraParams{.width = calibration.camera_image_width(),
- .height = calibration.camera_image_height(),
- .exposure = calibration.camera_exposure(),
- .brightness = calibration.camera_brightness(),
- .gain = calibration.camera_gain(),
- .fps = calibration.camera_fps()};
+::aos::vision::CameraParams GetCameraParams(const Calibration &calibration) {
+ ::aos::vision::CameraParams params;
+ params.set_width(calibration.camera_image_width());
+ params.set_height(calibration.camera_image_height());
+ params.set_exposure(calibration.camera_exposure());
+ params.set_brightness(calibration.camera_brightness());
+ params.set_gain(calibration.camera_gain());
+ params.set_fps(calibration.camera_fps());
+ return params;
}
int64_t Nanos(aos::monotonic_clock::duration time_diff) {
@@ -62,13 +65,14 @@
class ImageSender : public ImageStreamEvent {
public:
- ImageSender(int camera_index, camera::CameraParams params,
+ ImageSender(int camera_index, aos::vision::CameraParams params,
const std::string &fname, const std::string &ipadder, int port)
: ImageStreamEvent(fname, params),
camera_index_(camera_index),
udp_serv_(ipadder, 8080),
tcp_serv_(port),
- blob_filt_(ImageFormat(params.width, params.height), 40, 750, 250000),
+ blob_filt_(ImageFormat(params.width(), params.height()), 40, 750,
+ 250000),
finder_(0.25, 35) {
int index = 0;
while (true) {
@@ -94,9 +98,8 @@
DecodeJpeg(data, &image_);
auto fmt = image_.fmt();
- RangeImage rimg = DoThreshold(image_.get(), [](PixelRef &px) {
- return (px.g > 88);
- });
+ RangeImage rimg =
+ DoThreshold(image_.get(), [](PixelRef &px) { return (px.g > 88); });
// flip the right image as this camera is mount backward
if (camera_index_ == 0) {
@@ -202,11 +205,11 @@
private:
};
-void RunCamera(int camera_index, camera::CameraParams params,
+void RunCamera(int camera_index, aos::vision::CameraParams params,
const std::string &device, const std::string &ip_addr,
int port) {
- printf("Creating camera %d (%d, %d).\n", camera_index, params.width,
- params.height);
+ printf("Creating camera %d (%d, %d).\n", camera_index, params.width(),
+ params.height());
ImageSender strm(camera_index, params, device, ip_addr, port);
aos::events::EpollLoop loop;
diff --git a/y2016/vision/tools/BUILD b/y2016/vision/tools/BUILD
index a9e25ac..a7824c7 100644
--- a/y2016/vision/tools/BUILD
+++ b/y2016/vision/tools/BUILD
@@ -9,7 +9,7 @@
"//aos/vision/events:epoll_events",
"//aos/vision/events:gtk_event",
"//aos/vision/events:tcp_server",
- "//aos/vision/debug:debug_viewer",
+ "//aos/vision/debug:debug_window",
"//aos/vision/blob:range_image",
"//aos/vision/blob:stream_view",
"//y2016/vision:blob_filters",
diff --git a/y2016/vision/tools/blob_stream_replay.cc b/y2016/vision/tools/blob_stream_replay.cc
index f972fae..acf4d4b 100644
--- a/y2016/vision/tools/blob_stream_replay.cc
+++ b/y2016/vision/tools/blob_stream_replay.cc
@@ -4,6 +4,7 @@
#include <vector>
#include <memory>
#include <endian.h>
+#include <sys/stat.h>
#include <fstream>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
@@ -13,7 +14,6 @@
#include "aos/vision/image/image_stream.h"
#include "aos/vision/events/epoll_events.h"
#include "aos/vision/events/tcp_server.h"
-#include "aos/vision/debug/debug_viewer.h"
#include "aos/vision/blob/stream_view.h"
#include "y2016/vision/blob_filters.h"
// #include "y2016/vision/process_targets.h"
@@ -362,57 +362,57 @@
void DrawSuperSpeed() {
PixelRef color = {0, 255, 255};
// S
- overlay_.add_line(Vector<2>(200, 100), Vector<2>(100, 100), color);
- overlay_.add_line(Vector<2>(100, 100), Vector<2>(100, 300), color);
- overlay_.add_line(Vector<2>(100, 300), Vector<2>(200, 300), color);
- overlay_.add_line(Vector<2>(200, 300), Vector<2>(200, 500), color);
- overlay_.add_line(Vector<2>(200, 500), Vector<2>(100, 500), color);
+ overlay_.AddLine(Vector<2>(200, 100), Vector<2>(100, 100), color);
+ overlay_.AddLine(Vector<2>(100, 100), Vector<2>(100, 300), color);
+ overlay_.AddLine(Vector<2>(100, 300), Vector<2>(200, 300), color);
+ overlay_.AddLine(Vector<2>(200, 300), Vector<2>(200, 500), color);
+ overlay_.AddLine(Vector<2>(200, 500), Vector<2>(100, 500), color);
// U
- overlay_.add_line(Vector<2>(250, 100), Vector<2>(250, 500), color);
- overlay_.add_line(Vector<2>(250, 500), Vector<2>(350, 500), color);
- overlay_.add_line(Vector<2>(350, 500), Vector<2>(350, 100), color);
+ overlay_.AddLine(Vector<2>(250, 100), Vector<2>(250, 500), color);
+ overlay_.AddLine(Vector<2>(250, 500), Vector<2>(350, 500), color);
+ overlay_.AddLine(Vector<2>(350, 500), Vector<2>(350, 100), color);
// P
- overlay_.add_line(Vector<2>(400, 100), Vector<2>(400, 500), color);
- overlay_.add_line(Vector<2>(400, 100), Vector<2>(500, 100), color);
- overlay_.add_line(Vector<2>(500, 100), Vector<2>(500, 300), color);
- overlay_.add_line(Vector<2>(500, 300), Vector<2>(400, 300), color);
+ overlay_.AddLine(Vector<2>(400, 100), Vector<2>(400, 500), color);
+ overlay_.AddLine(Vector<2>(400, 100), Vector<2>(500, 100), color);
+ overlay_.AddLine(Vector<2>(500, 100), Vector<2>(500, 300), color);
+ overlay_.AddLine(Vector<2>(500, 300), Vector<2>(400, 300), color);
// E
- overlay_.add_line(Vector<2>(550, 100), Vector<2>(550, 500), color);
- overlay_.add_line(Vector<2>(550, 100), Vector<2>(650, 100), color);
- overlay_.add_line(Vector<2>(550, 300), Vector<2>(650, 300), color);
- overlay_.add_line(Vector<2>(550, 500), Vector<2>(650, 500), color);
+ overlay_.AddLine(Vector<2>(550, 100), Vector<2>(550, 500), color);
+ overlay_.AddLine(Vector<2>(550, 100), Vector<2>(650, 100), color);
+ overlay_.AddLine(Vector<2>(550, 300), Vector<2>(650, 300), color);
+ overlay_.AddLine(Vector<2>(550, 500), Vector<2>(650, 500), color);
// R
- overlay_.add_line(Vector<2>(700, 100), Vector<2>(700, 500), color);
- overlay_.add_line(Vector<2>(700, 100), Vector<2>(800, 100), color);
- overlay_.add_line(Vector<2>(800, 100), Vector<2>(800, 300), color);
- overlay_.add_line(Vector<2>(800, 300), Vector<2>(700, 300), color);
- overlay_.add_line(Vector<2>(700, 350), Vector<2>(800, 500), color);
+ overlay_.AddLine(Vector<2>(700, 100), Vector<2>(700, 500), color);
+ overlay_.AddLine(Vector<2>(700, 100), Vector<2>(800, 100), color);
+ overlay_.AddLine(Vector<2>(800, 100), Vector<2>(800, 300), color);
+ overlay_.AddLine(Vector<2>(800, 300), Vector<2>(700, 300), color);
+ overlay_.AddLine(Vector<2>(700, 350), Vector<2>(800, 500), color);
// S
- overlay_.add_line(Vector<2>(200, 550), Vector<2>(100, 550), color);
- overlay_.add_line(Vector<2>(100, 550), Vector<2>(100, 750), color);
- overlay_.add_line(Vector<2>(100, 750), Vector<2>(200, 750), color);
- overlay_.add_line(Vector<2>(200, 750), Vector<2>(200, 950), color);
- overlay_.add_line(Vector<2>(200, 950), Vector<2>(100, 950), color);
+ overlay_.AddLine(Vector<2>(200, 550), Vector<2>(100, 550), color);
+ overlay_.AddLine(Vector<2>(100, 550), Vector<2>(100, 750), color);
+ overlay_.AddLine(Vector<2>(100, 750), Vector<2>(200, 750), color);
+ overlay_.AddLine(Vector<2>(200, 750), Vector<2>(200, 950), color);
+ overlay_.AddLine(Vector<2>(200, 950), Vector<2>(100, 950), color);
// P
- overlay_.add_line(Vector<2>(250, 550), Vector<2>(250, 950), color);
- overlay_.add_line(Vector<2>(250, 550), Vector<2>(350, 550), color);
- overlay_.add_line(Vector<2>(350, 550), Vector<2>(350, 750), color);
- overlay_.add_line(Vector<2>(350, 750), Vector<2>(250, 750), color);
+ overlay_.AddLine(Vector<2>(250, 550), Vector<2>(250, 950), color);
+ overlay_.AddLine(Vector<2>(250, 550), Vector<2>(350, 550), color);
+ overlay_.AddLine(Vector<2>(350, 550), Vector<2>(350, 750), color);
+ overlay_.AddLine(Vector<2>(350, 750), Vector<2>(250, 750), color);
// E
- overlay_.add_line(Vector<2>(400, 550), Vector<2>(400, 950), color);
- overlay_.add_line(Vector<2>(400, 550), Vector<2>(500, 550), color);
- overlay_.add_line(Vector<2>(400, 750), Vector<2>(500, 750), color);
- overlay_.add_line(Vector<2>(400, 950), Vector<2>(500, 950), color);
+ overlay_.AddLine(Vector<2>(400, 550), Vector<2>(400, 950), color);
+ overlay_.AddLine(Vector<2>(400, 550), Vector<2>(500, 550), color);
+ overlay_.AddLine(Vector<2>(400, 750), Vector<2>(500, 750), color);
+ overlay_.AddLine(Vector<2>(400, 950), Vector<2>(500, 950), color);
// E
- overlay_.add_line(Vector<2>(550, 550), Vector<2>(550, 950), color);
- overlay_.add_line(Vector<2>(550, 550), Vector<2>(650, 550), color);
- overlay_.add_line(Vector<2>(550, 750), Vector<2>(650, 750), color);
- overlay_.add_line(Vector<2>(550, 950), Vector<2>(650, 950), color);
+ overlay_.AddLine(Vector<2>(550, 550), Vector<2>(550, 950), color);
+ overlay_.AddLine(Vector<2>(550, 550), Vector<2>(650, 550), color);
+ overlay_.AddLine(Vector<2>(550, 750), Vector<2>(650, 750), color);
+ overlay_.AddLine(Vector<2>(550, 950), Vector<2>(650, 950), color);
// D
- overlay_.add_line(Vector<2>(700, 550), Vector<2>(700, 950), color);
- overlay_.add_line(Vector<2>(700, 550), Vector<2>(800, 575), color);
- overlay_.add_line(Vector<2>(800, 575), Vector<2>(800, 925), color);
- overlay_.add_line(Vector<2>(800, 925), Vector<2>(700, 950), color);
+ overlay_.AddLine(Vector<2>(700, 550), Vector<2>(700, 950), color);
+ overlay_.AddLine(Vector<2>(700, 550), Vector<2>(800, 575), color);
+ overlay_.AddLine(Vector<2>(800, 575), Vector<2>(800, 925), color);
+ overlay_.AddLine(Vector<2>(800, 925), Vector<2>(700, 950), color);
}
void UpdateNewTime(int new_delta) {
@@ -524,9 +524,9 @@
}
void DrawCross(PixelLinesOverlay &overlay, Vector<2> center, PixelRef color) {
- overlay.add_line(Vector<2>(center.x() - 25, center.y()),
+ overlay.AddLine(Vector<2>(center.x() - 25, center.y()),
Vector<2>(center.x() + 25, center.y()), color);
- overlay.add_line(Vector<2>(center.x(), center.y() - 25),
+ overlay.AddLine(Vector<2>(center.x(), center.y() - 25),
Vector<2>(center.x(), center.y() + 25), color);
}
diff --git a/y2017/vision/BUILD b/y2017/vision/BUILD
index b70e67f..c7b4b7e 100644
--- a/y2017/vision/BUILD
+++ b/y2017/vision/BUILD
@@ -20,6 +20,9 @@
proto_cc_library(
name = 'vision_config',
src = 'vision_config.proto',
+ deps = [
+ '//aos/vision/image:camera_params',
+ ],
)
cc_binary(
diff --git a/y2017/vision/target_finder.cc b/y2017/vision/target_finder.cc
index e39fe73..1f2c46d 100644
--- a/y2017/vision/target_finder.cc
+++ b/y2017/vision/target_finder.cc
@@ -105,7 +105,6 @@
aos::vision::RangeImage TargetFinder::Threshold(aos::vision::ImagePtr image) {
return aos::vision::DoThreshold(image, [&](aos::vision::PixelRef &px) {
if (px.g > 88) {
- return true;
uint8_t min = std::min(px.b, px.r);
uint8_t max = std::max(px.b, px.r);
if (min >= px.g || max >= px.g) return false;
diff --git a/y2017/vision/target_sender.cc b/y2017/vision/target_sender.cc
index 548d01d..8eb13f5 100644
--- a/y2017/vision/target_sender.cc
+++ b/y2017/vision/target_sender.cc
@@ -2,6 +2,7 @@
#include <google/protobuf/text_format.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/stat.h>
#include <fstream>
#include <iostream>
#include <memory>
@@ -76,13 +77,9 @@
std::ofstream ofst_;
};
-ImageFormat GetImageFormat(const CameraSettings ¶ms) {
- return ImageFormat{params.width(), params.height()};
-}
-
class ImageSender : public ImageStreamEvent {
public:
- ImageSender(camera::CameraParams params, GameSpecific game_cfg,
+ ImageSender(aos::vision::CameraParams params, GameSpecific game_cfg,
const std::string &fname, const std::string &ipadder, int port)
: ImageStreamEvent(fname, params),
game_cfg_(game_cfg),
@@ -181,17 +178,11 @@
private:
};
-void RunCamera(CameraSettings settings, GameSpecific game_cfg,
+void RunCamera(aos::vision::CameraParams settings, GameSpecific game_cfg,
const std::string &device, const std::string &ip_addr,
int port) {
printf("Creating camera (%dx%d).\n", settings.width(), settings.height());
- camera::CameraParams params = {settings.width(),
- settings.height(),
- settings.exposure(),
- settings.brightness(),
- 0,
- (int32_t)settings.fps()};
- ImageSender strm(params, game_cfg, device, ip_addr, port);
+ ImageSender strm(settings, game_cfg, device, ip_addr, port);
aos::events::EpollLoop loop;
loop.Add(strm.GetTCPServ());
diff --git a/y2017/vision/vision_config.proto b/y2017/vision/vision_config.proto
index 0bb7279..5501507 100644
--- a/y2017/vision/vision_config.proto
+++ b/y2017/vision/vision_config.proto
@@ -1,31 +1,9 @@
syntax = "proto2";
+import "aos/vision/image/camera_params.proto";
+
package y2017.vision;
-// Stores configuration for camera related settings and specs.
-message CameraSettings {
- // The focal length of the camera in pixels.
- optional double focal_length = 1 [default = 1418.6];
-
- // Width of the image.
- optional int32 width = 2 [default = 1280];
-
- // Height of the image.
- optional int32 height = 3 [default = 960];
-
- // Exposure setting.
- optional int32 exposure = 4 [default = 10];
-
- // Brightness setting.
- optional int32 brightness = 5 [default = 128];
-
- // Hardware gain multiplier on pixel values.
- optional double gain = 6 [default = 1.0];
-
- // Frames per second to run camera.
- optional double fps = 7 [default = 30.0];
-}
-
message GameSpecific {
// Needs more woojy.
optional int32 woojy = 1;
@@ -51,9 +29,9 @@
// Map robot name to the robot dependent configuration.
map<string, RobotConfig> robot_configs = 1;
- // Parameters for camera bringup.
- optional CameraSettings camera_params = 2;
+ // Year independent camera parameters.
+ optional aos.vision.CameraParams camera_params = 3;
// Parameters for this specific game
- optional GameSpecific game_params = 3;
+ optional GameSpecific game_params = 4;
}