Delete the vision code
It hasn't compiled for several years now.
Change-Id: I56bdaaea05a4488895ec382e36f3623c5f05e43d
diff --git a/aos/linux_code/output/BUILD b/aos/linux_code/output/BUILD
deleted file mode 100644
index bcd63bd..0000000
--- a/aos/linux_code/output/BUILD
+++ /dev/null
@@ -1,22 +0,0 @@
-package(default_visibility = ['//visibility:public'])
-
-cc_library(
- name = 'http_server',
- srcs = [
- 'HTTPServer.cpp',
- 'evhttp_ctemplate_emitter.cc',
- 'ctemplate_cache.cc',
- ],
- hdrs = [
- 'HTTPServer.h',
- 'evhttp_ctemplate_emitter.h',
- 'ctemplate_cache.h',
- ],
- deps = [
- '//third_party/libevent',
- '//third_party/ctemplate',
- '//aos/common:once',
- '//aos/common:scoped_fd',
- '//aos/common/logging',
- ],
-)
diff --git a/aos/linux_code/output/HTTPServer.cpp b/aos/linux_code/output/HTTPServer.cpp
deleted file mode 100644
index d18572b..0000000
--- a/aos/linux_code/output/HTTPServer.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-#include "aos/linux_code/output/HTTPServer.h"
-
-#include <inttypes.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-
-#include <memory>
-
-#include "event2/event.h"
-
-#include "aos/common/scoped_fd.h"
-#include "aos/common/unique_malloc_ptr.h"
-
-namespace aos {
-namespace http {
-
-HTTPServer::HTTPServer(const char *directory, uint16_t port) :
- directory_(directory), base_(event_base_new()), http_(evhttp_new(base_)) {
- if (base_ == NULL) {
- LOG(FATAL, "couldn't create an event_base\n");
- }
- if (http_ == NULL) {
- LOG(FATAL, "couldn't create an evhttp\n");
- }
- if (evhttp_bind_socket(http_, "0.0.0.0", port) != 0) {
- LOG(FATAL, "evhttp_bind_socket(%p, \"0.0.0.0\", %" PRIu16 ") failed\n",
- http_, port);
- }
- evhttp_set_gencb(http_, StaticServeFile, this);
-}
-
-void HTTPServer::AddPage(const std::string &path,
- void (*handler)(evhttp_request *, void *), void *data) {
- switch (evhttp_set_cb(http_, path.c_str(), handler, data)) {
- case 0:
- LOG(DEBUG, "set callback handler for '%s'\n", path.c_str());
- break;
- case -1:
- LOG(INFO, "changed callback handler for '%s'\n", path.c_str());
- break;
- default:
- LOG(WARNING, "evhttp_set_cb(%p, %s, %p, %p) failed\n", http_, path.c_str(),
- handler, data);
- break;
- }
-}
-
-void HTTPServer::AddStandardHeaders(evhttp_request *request) {
- if (evhttp_add_header(evhttp_request_get_output_headers(request),
- "Server", "aos::HTTPServer/0.0") == -1) {
- LOG(WARNING, "adding Server header failed\n");
- }
-}
-
-namespace {
-// All of these functions return false, NULL, or -1 if they fail (and send back
-// an error).
-
-// Returns the path of the file that is being requested.
-const char *GetPath(evhttp_request *request) {
- // Docs are unclear whether this needs freeing, but it looks like it just
- // returns an internal field of the request.
- // Running valgrind with no freeing of uri or path doesn't report anything
- // related to this code.
- const evhttp_uri *uri = evhttp_request_get_evhttp_uri(request);
- const char *path = evhttp_uri_get_path(uri);
- if (path == NULL) {
- evhttp_send_error(request, HTTP_BADREQUEST, "need a path");
- return NULL;
- }
- if (strstr(path, "..") != NULL) {
- evhttp_send_error(request, HTTP_NOTFOUND, "no .. allowed!!");
- return NULL;
- }
- return path;
-}
-// Returns an fd open for reading for the file at "directory/path".
-int OpenFile(evhttp_request *request, const char *path,
- const char *directory) {
- char *temp;
- if (asprintf(&temp, "%s/%s", directory, path) == -1) {
- PLOG(WARNING, "asprintf(%p, \"%%s/%%s\", %p, %p) failed",
- &temp, directory, path);
- evhttp_send_error(request, HTTP_INTERNAL, NULL);
- return -1;
- }
- const unique_c_ptr<char> filename(temp);
- ScopedFD file(open(filename.get(), O_RDONLY));
- if (!file) {
- if (errno == ENOENT) {
- evhttp_send_error(request, HTTP_NOTFOUND, NULL);
- return -1;
- }
- PLOG(ERROR, "open('%s', 0) failed", filename.get(),
- evhttp_send_error(request, HTTP_INTERNAL, NULL);
- return -1;
- }
- return file.release();
-}
-// Returns the size of the file specified by the given fd.
-off_t GetSize(int file) {
- struct stat info;
- if (fstat(file, &info) == -1) {
- PLOG(ERROR, "stat(%d, %p) failed", file, &info);
- return -1;
- }
- return info.st_size;
-}
-bool SendFileResponse(evhttp_request *request, int file_num) {
- ScopedFD file(file_num);
- const off_t size = GetSize(file.get());
- if (size == -1) {
- evhttp_send_error(request, HTTP_INTERNAL, NULL);
- return false;
- }
- evbuffer *const buf = evhttp_request_get_output_buffer(request);
- if (evbuffer_add_file(buf, file.get(), 0, size) == -1) {
- LOG(WARNING, "evbuffer_add_file(%p, %d, 0, %jd) failed\n", buf,
- file.get(), static_cast<intmax_t>(size));
- evhttp_send_error(request, HTTP_INTERNAL, NULL);
- return false;
- } else {
- // it succeeded, so evhttp takes ownership
- file.release();
- }
- evhttp_send_reply(request, HTTP_OK, NULL, NULL);
- return true;
-}
-
-} // namespace
-void HTTPServer::ServeFile(evhttp_request *request) {
- AddStandardHeaders(request);
-
- const char *path = GetPath(request);
- if (path == NULL) return;
-
- ScopedFD file(OpenFile(request, path, directory_));
- if (!file) return;
-
- if (!SendFileResponse(request, file.release())) return;
-}
-
-void HTTPServer::Run() {
- event_base_dispatch(base_);
- LOG(FATAL, "event_base_dispatch returned\n");
-}
-
-} // namespace http
-} // namespace aos
diff --git a/aos/linux_code/output/HTTPServer.h b/aos/linux_code/output/HTTPServer.h
deleted file mode 100644
index 99eb295..0000000
--- a/aos/linux_code/output/HTTPServer.h
+++ /dev/null
@@ -1,58 +0,0 @@
-#include "event2/buffer.h"
-#include "event2/http.h"
-
-#include <string>
-
-namespace aos {
-namespace http {
-
-// An HTTP server that serves files from a directory using libevent.
-// Also allows configuring certain URLs to be dynamically generated.
-class HTTPServer {
- public:
- HTTPServer(const char *directory, uint16_t port);
- // Starts serving pages.
- // Might not clean up everything before returning.
- void Run();
- protected:
- template<class T> class MemberHandler {
- public:
- typedef void (T::*Handler)(evhttp_request *);
- struct Holder {
- T *self;
- Handler handler;
- };
- static void Call(evhttp_request *request, void *handler_in) {
- const Holder *const holder = static_cast<Holder *>(handler_in);
- AddStandardHeaders(request);
- ((holder->self)->*(holder->handler))(request);
- }
- };
- void AddPage(const std::string &path, void (*handler)(evhttp_request *, void *),
- void *data);
- template<class T> void AddPage(const std::string &path,
- typename MemberHandler<T>::Handler handler,
- T *self) {
- // have to put "typename" in, so the typedef makes it clearer
- typedef typename MemberHandler<T>::Holder HolderType;
- AddPage(path, MemberHandler<T>::Call, new HolderType{self, handler});
- }
- // This gets set up as the generic handler.
- // It can also be called separately to serve the file that the request is
- // requesting from the filesystem.
- void ServeFile(evhttp_request *request);
- private:
- // The directory where files to be served come from.
- const char *directory_;
- // The main libevent structure.
- event_base *const base_;
- // The libevent HTTP server handle.
- evhttp *const http_;
- static void AddStandardHeaders(evhttp_request *request);
- static void StaticServeFile(evhttp_request *request, void *self) {
- static_cast<HTTPServer *>(self)->ServeFile(request);
- }
-};
-
-} // namespace http
-} // namespace aos
diff --git a/aos/linux_code/output/ctemplate_cache.cc b/aos/linux_code/output/ctemplate_cache.cc
deleted file mode 100644
index cf961c6..0000000
--- a/aos/linux_code/output/ctemplate_cache.cc
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "aos/linux_code/output/ctemplate_cache.h"
-
-#include "aos/linux_code/configuration.h"
-#include "aos/common/once.h"
-
-namespace aos {
-namespace http {
-
-namespace {
-ctemplate::TemplateCache *CreateTemplateCache() {
- ctemplate::TemplateCache *r = new ctemplate::TemplateCache();
-
- r->SetTemplateRootDirectory(configuration::GetRootDirectory());
-
- return r;
-}
-} // namespace
-ctemplate::TemplateCache *get_template_cache() {
- static Once<ctemplate::TemplateCache> once(CreateTemplateCache);
- return once.Get();
-}
-
-} // namespace http
-} // namespace aos
diff --git a/aos/linux_code/output/ctemplate_cache.h b/aos/linux_code/output/ctemplate_cache.h
deleted file mode 100644
index 7e5dc3d..0000000
--- a/aos/linux_code/output/ctemplate_cache.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "ctemplate/template_cache.h"
-
-namespace aos {
-namespace http {
-
-// Retrieves the cache used by all of the aos functions etc.
-// This cache will have its root directory set to the directory where the
-// executable is running from.
-ctemplate::TemplateCache *get_template_cache();
-
-} // namespace http
-} // namespace aos
diff --git a/aos/linux_code/output/evhttp_ctemplate_emitter.cc b/aos/linux_code/output/evhttp_ctemplate_emitter.cc
deleted file mode 100644
index 2301ffb..0000000
--- a/aos/linux_code/output/evhttp_ctemplate_emitter.cc
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "aos/linux_code/output/evhttp_ctemplate_emitter.h"
-
-#include "aos/common/logging/logging.h"
-
-namespace aos {
-namespace http {
-
-void EvhttpCtemplateEmitter::Emit(const char *s, size_t slen) {
- if (error_) return;
- if (evbuffer_add(buf_, s, slen) != 0) {
- LOG(ERROR, "evbuffer_add(%p, %p, %zd) failed\n",
- buf_, s, slen);
- error_ = true;
- }
-}
-
-} // namespace http
-} // namespace aos
diff --git a/aos/linux_code/output/evhttp_ctemplate_emitter.h b/aos/linux_code/output/evhttp_ctemplate_emitter.h
deleted file mode 100644
index 5b8e96a..0000000
--- a/aos/linux_code/output/evhttp_ctemplate_emitter.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#ifndef AOS_LINUX_CODE_OUTPUT_EVHTTP_CTEMPLATE_EMITTER_H_
-#define AOS_LINUX_CODE_OUTPUT_EVHTTP_CTEMPLATE_EMITTER_H_
-
-#include <string.h>
-
-#include "event2/buffer.h"
-#include "ctemplate/template_emitter.h"
-
-namespace aos {
-namespace http {
-
-// Writes everything directly into an evbuffer*.
-// Handles errors by refusing to write anything else into the buffer and storing
-// the state (which can be retrieved with error()).
-class EvhttpCtemplateEmitter : public ctemplate::ExpandEmitter {
- public:
- EvhttpCtemplateEmitter(evbuffer *buf) : buf_(buf), error_(false) {}
- virtual void Emit(char c) { Emit(&c, 1); };
- virtual void Emit(const std::string& s) { Emit(s.data(), s.size()); };
- virtual void Emit(const char* s) { Emit(s, strlen(s)); }
- virtual void Emit(const char* s, size_t slen);
- // Retrieves whether or not there has been an error. If true, the error will
- // already have been logged.
- bool error() { return error_; }
-
- private:
- evbuffer *const buf_;
- bool error_;
-};
-
-} // namespace http
-} // namespace aos
-
-#endif // AOS_LINUX_CODE_OUTPUT_EVHTTP_CTEMPLATE_EMITTER_H_
diff --git a/aos/linux_code/output/output.gyp b/aos/linux_code/output/output.gyp
deleted file mode 100644
index f697630..0000000
--- a/aos/linux_code/output/output.gyp
+++ /dev/null
@@ -1,24 +0,0 @@
-{
- 'targets': [
- {
- 'target_name': 'http_server',
- 'type': 'static_library',
- 'sources': [
- 'HTTPServer.cpp',
- 'evhttp_ctemplate_emitter.cc',
- 'ctemplate_cache.cc',
- ],
- 'dependencies': [
- '<(EXTERNALS):libevent',
- '<(EXTERNALS):ctemplate',
- '<(AOS)/common/common.gyp:once',
- '<(AOS)/common/common.gyp:scoped_fd',
- '<(AOS)/build/aos.gyp:logging',
- ],
- 'export_dependent_settings': [
- '<(EXTERNALS):libevent',
- '<(EXTERNALS):ctemplate',
- ],
- },
- ],
-}
diff --git a/vision/BUILD b/vision/BUILD
deleted file mode 100644
index 1ea52ca..0000000
--- a/vision/BUILD
+++ /dev/null
@@ -1,37 +0,0 @@
-package(default_visibility = ['//visibility:public'])
-
-cc_binary(
- name = 'OpenCVWorkTask',
- srcs = [
- 'OpenCVWorkTask.cpp',
- 'CameraProcessor.cpp',
- 'JPEGRoutines.cpp',
- 'OpenCVWorkTask.h',
- 'CameraProcessor.h',
- 'JPEGRoutines.h',
- ],
- deps = [
- '//aos/linux_code:init',
- '//aos/common:time',
- '//third_party/libevent',
- '//third_party/libjpeg',
- '//third_party/opencv',
- '//aos/linux_code/camera:buffers',
- '//frc971/queues:queues',
- ],
-)
-
-cc_binary(
- name = 'GoalMaster',
- srcs = [
- 'GoalMaster.cpp',
- 'SensorProcessor.cpp',
- 'SensorProcessor.h',
- ],
- deps = [
- '//aos/linux_code:init',
- '//aos/common:time',
- '//frc971/queues:queues',
- '//aos/common/logging',
- ],
-)
diff --git a/vision/BinaryServer.cpp b/vision/BinaryServer.cpp
deleted file mode 100644
index c21a8b3..0000000
--- a/vision/BinaryServer.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-#include "vision/BinaryServer.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include <string.h>
-#include <vector>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-
-#include "aos/externals/libjpeg/include/jpeglib.h"
-#include "aos/linux_code/camera/Buffers.h"
-#include "aos/common/time.h"
-
-namespace frc971 {
-namespace vision {
-
-static void echo_read_cb(struct bufferevent *bev, void * /*ctx*/) {
- struct evbuffer *input = bufferevent_get_input(bev);
- struct evbuffer *output = bufferevent_get_output(bev);
-
- size_t len = evbuffer_get_length(input);
- char *data;
- data = (char *)malloc(len);
- evbuffer_copyout(input, data, len);
-
- printf("we got some data: %s\n", data);
-
- evbuffer_add_buffer(output, input);
-}
-
-void BinaryServer::ErrorEvent(struct bufferevent *bev, short events) {
- if (events & BEV_EVENT_ERROR) perror("Error from bufferevent");
- if (events & (BEV_EVENT_EOF | BEV_EVENT_ERROR)) {
- have_id = false;
- bufferevent_free(bev);
- }
-}
-
-void BinaryServer::Accept(struct evconnlistener *listener, evutil_socket_t fd,
- struct sockaddr * /*address*/, int /*socklen*/) {
- struct event_base *base = evconnlistener_get_base(listener);
- if (!have_id) {
- struct bufferevent *bev =
- bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE);
- _output = bufferevent_get_output(bev);
- _bufev = bev;
- have_id = true;
- int no_delay_flag = 1;
- setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &no_delay_flag,
- sizeof(no_delay_flag));
-
- bufferevent_setcb(bev, echo_read_cb, NULL, StaticErrorEvent, this);
-
- bufferevent_enable(bev, EV_READ | EV_WRITE);
- }
-}
-static void accept_error_cb(struct evconnlistener *listener, void * /*ctx*/) {
- struct event_base *base = evconnlistener_get_base(listener);
- int err = EVUTIL_SOCKET_ERROR();
- fprintf(stderr, "Got an error %d (%s) on the listener. "
- "Shutting down.\n",
- err, evutil_socket_error_to_string(err));
-
- event_base_loopexit(base, NULL);
-}
-
-void BinaryServer::StartServer(uint16_t port) {
- _fd = socket(AF_INET, SOCK_STREAM, 0);
- struct sockaddr_in sin;
- memset(&sin, 0, sizeof(sin));
- sin.sin_family = AF_INET;
- sin.sin_port = htons(port);
- sin.sin_addr.s_addr = inet_addr("0.0.0.0");
-
- listener = evconnlistener_new_bind(
- _base, StaticAccept, this, LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE, -1,
- (struct sockaddr *)(void *)&sin, sizeof(sin));
-
- if (!listener) {
- fprintf(stderr, "%s:%d: Couldn't create listener\n", __FILE__, __LINE__);
- exit(-1);
- }
-
- evconnlistener_set_error_cb(listener, accept_error_cb);
-}
-
-void BinaryServer::Notify(int fd, short /*what*/) {
- char notes[4096];
- int count = read(fd, notes, 4096);
- if (count == 0) {
- close(fd);
- fprintf(stderr, "%s:%d: Error No cheeze from OpenCV task!!!\n", __FILE__,
- __LINE__);
- exit(-1);
- }
- printf("notified!: %d\n", count);
- if (have_id) {
- printf("got someone to read my stuff!\n");
- char *binary_data;
- size_t len;
- if (_notify->GetData(&binary_data, &len)) {
- printf("here is for sending\n");
- evbuffer_add_reference(_output, binary_data, len,
- PacketNotifier::StaticDataSent, _notify);
- printf("this is how sending went %d\n",
- bufferevent_flush(_bufev, EV_WRITE, BEV_FLUSH));
- }
- }
-}
-
-// Constructor
-BinaryServer::BinaryServer(uint16_t port,
- frc971::vision::PacketNotifier *notify)
- : _base(event_base_new()) {
- have_id = false;
- StartServer(port);
- _notify = notify;
- frame_notify = event_new(_base, notify->RecieverFD(), EV_READ | EV_PERSIST,
- StaticNotify, this);
- event_add(frame_notify, NULL);
- event_base_dispatch(_base);
-}
-
-} // namespace vision
-} // namespace frc971
diff --git a/vision/BinaryServer.h b/vision/BinaryServer.h
deleted file mode 100644
index f33ee21..0000000
--- a/vision/BinaryServer.h
+++ /dev/null
@@ -1,57 +0,0 @@
-#ifndef FRC971_VISION_BINARY_SERVER_H_
-#define FRC971_VISION_BINARY_SERVER_H_
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include "event2/buffer.h"
-#include "event2/event.h"
-#include "event2/listener.h"
-#include "event2/bufferevent.h"
-
-#include "aos/common/mutex.h"
-
-#include "vision/PacketNotifier.h"
-
-namespace frc971 {
-namespace vision {
-
-/* This runs the libevent loop and interfaces in with the sockets provided from the PacketNotifier
- * to allow a secondary process to focus primarily on doing processing and then feeding this task.
- */
-class BinaryServer {
- public:
- BinaryServer(uint16_t port,PacketNotifier *notify);
-
-
- void StartServer(uint16_t port);
- private:
- event_base *const _base;
- int _fd;
- PacketNotifier *_notify;
- bool have_id;
- int _client_fd;
- struct event *frame_notify;
- struct evbuffer *_output;
- struct bufferevent *_bufev;
- struct evconnlistener *listener;
- void Accept(evconnlistener *listener, evutil_socket_t fd,
- struct sockaddr* /*address*/, int /*socklen*/);
- void Notify(int /*fd*/, short /*what*/);
- void ErrorEvent(struct bufferevent *bev,short events);
- static void StaticAccept(evconnlistener *listener, evutil_socket_t fd,
- struct sockaddr *address, int socklen,void *self){
- ((BinaryServer *)(self))->Accept(listener, fd, address, socklen);
- }
- static void StaticNotify(int fd, short what, void *self){
- ((BinaryServer *)(self))->Notify(fd, what);
- }
- static void StaticErrorEvent(struct bufferevent *bev,short events,void *self){
- ((BinaryServer *)(self))->ErrorEvent(bev,events);
- }
-};
-
-} // namespace vision
-} // namespace frc971
-
-#endif // FRC971_VISION_BINARY_SERVER_H_
diff --git a/vision/CameraProcessor.cpp b/vision/CameraProcessor.cpp
deleted file mode 100644
index 856e12b..0000000
--- a/vision/CameraProcessor.cpp
+++ /dev/null
@@ -1,466 +0,0 @@
-#include "vision/CameraProcessor.h"
-#include "aos/common/logging/logging.h"
-
-//#define LOCAL_DEBUG 1
-
-// create a new target
-Target::Target(std::vector<cv::Point> new_contour,
- std::vector<cv::Point> new_raw_contour,
- FullRect new_rect, int new_weight, bool _is_90) {
- this_contour = new_contour;
- raw_contour = new_raw_contour;
- rect = new_rect;
- weight = new_weight;
- height = getHeight(_is_90);
-}
-
-// calculate distance to target
-double Target::getHeight(bool is_90) {
- // The 780.3296 is at full resolution 640x480, and we need
- // to scale back to 320x240
- //static const double cam_l = 780.3296 / 2.0;
- ////static const double cam_d = 20.78096;
- double height;
- if (is_90) {
- height = ((rect.ul.x - rect.ur.x) +
- (rect.bl.x - rect.br.x)) / 2.0;
- } else {
- height = ((rect.ur.y + rect.ul.y) -
- (rect.br.y + rect.bl.y)) / 2.0;
- }
- //return cam_l * 12.0 / height;
- return height;
-}
-
-void Target::refineTarget() {
- printf("okay refined\n");
-}
-
-FullRect::FullRect() {
- ur.x = -1;
- ur.y = -1;
- ul.x = -1;
- ul.y = -1;
- br.x = -1;
- br.y = -1;
- bl.x = -1;
- bl.y = -1;
-}
-
-// turns a contour into easier to access structure
-FullRect calcFullRect(std::vector<cv::Point> *contour){
- FullRect rect;
- for(int i=0; i<4; i++){
- cv::Point2f pt = (*contour)[i];
- rect.centroid.x += pt.x;
- rect.centroid.y += pt.y;
- }
- rect.centroid.x /= 4;
- rect.centroid.y /= 4;
- for(int i=0; i<4; i++){
- cv::Point2f pt = (*contour)[i];
- if(pt.y > rect.centroid.y ){
- if(pt.x > rect.centroid.x){
- if (rect.ul.x < 0) {
- rect.ul = pt;
- } else {
- rect.ur = pt;
- }
- }else{
- if (rect.ur.x < 0) {
- rect.ur = pt;
- } else {
- rect.ul = pt;
- }
- }
- if (rect.ul.x > 0 && rect.ur.x > 0) {
- // both are set, so if we got it wrong correct it here
- if (rect.ul.x > rect.ur.x) {
- pt = rect.ur;
- rect.ur = rect.ul;
- rect.ul = pt;
- }
- }
- }else{
- if(pt.x > rect.centroid.x){
- if (rect.bl.x < 0) {
- rect.bl = pt;
- } else {
- rect.br = pt;
- }
- }else{
- if (rect.br.x < 0) {
- rect.br = pt;
- } else {
- rect.bl = pt;
- }
- }
- if (rect.bl.x > 0 && rect.br.x > 0) {
- // both are set, so if we got it wrong correct it here
- if (rect.bl.x > rect.br.x) {
- pt = rect.br;
- rect.br = rect.bl;
- rect.bl = pt;
- }
- }
- }
- }
- return rect;
-}
-
-// quickly remove targets that do not fit a very broad set of constraints
-bool cullObvious(FullRect rect, double outside_size){
- // first check that could see a target this size
- // Calculated from dave's simulation, shloud be 850 and 72000 if filled
- if((outside_size < 500) || (outside_size > 90000)){
- return false;
- }
- // Targets on the edge are at best inaccurate.
- // In this case, we just want to point the right way,
- // so this is no longer a valid assumption.
- /*if( rect.ur.x < 2 || rect.ur.y < 2 || rect.ur.x > 637 || rect.ur.y > 477 ||
- rect.ul.x < 2 || rect.ul.y < 2 || rect.ul.x > 637 || rect.ul.y > 477 ||
- rect.br.x < 2 || rect.br.y < 2 || rect.br.x > 637 || rect.br.y > 477 ||
- rect.bl.x < 2 || rect.bl.y < 2 || rect.bl.x > 637 || rect.bl.y > 477){
- return false;
- }*/
- // make sure the sides are close to the right ratio of a rect
- // some really odd shapes get confusing
- double ratio = norm(rect.ur-rect.ul)/norm(rect.br-rect.bl);
- if( ratio < .7 || ratio > 1.4 ) {
- return false;
- }
- ratio = norm(rect.ur-rect.br)/norm(rect.ul-rect.bl);
- if( ratio < .7 || ratio > 1.4 ) {
- return false;
- }
-
- return true;
-}
-
-// sum over values between these two points and normalize
-// see Bresenham's Line Algorithm for the logic of moving
-// over all the pixels between these two points.
-double ProcessorData::calcHistComponent(
- cv::Point2i start,
- cv::Point2i end,
- cv::Mat thresh_img){
- int dx = abs(end.x - start.x);
- int dy = abs(end.y - start.y);
- int sx = (start.x < end.x) ? 1 : -1;
- int sy = (start.y < end.y) ? 1 : -1;
- int error = dx-dy;
-
- int total = 0;
- int value = 0;
- int total_error;
-#if LOCAL_DEBUG
- IplImage gd = *global_display;
-#endif
- IplImage ti = thresh_img;
- while(1){
- total++;
-
- uchar* ptr = (uchar*) (ti.imageData + start.y * ti.widthStep + start.x);
- if((int) *ptr) value++;
- // draw line checked
-#if LOCAL_DEBUG
- uchar* ptr2 = (uchar*) (gd.imageData + start.y * gd.widthStep + start.x*3);
- *ptr2++ = 0;
- *ptr2++ = 255;
- *ptr2 = 0;
-#endif
- if(start.x == end.x && start.y == end.y) break;
- total_error = 2 * error;
- if(total_error > -dy){
- error -= dy;
- start.x += sx;
- }
- if(total_error < dx){
- error += dx;
- start.y += sy;
- }
- }
- return (double)value/(double)total;
-}
-
-// just a distance function
-double chiSquared(int length, double* histA, double* histB){
- double sum = 0;
- for(int i=0; i<length;i++){
- double diff = *(histB+i) - *(histA+i);
- sum += (diff * diff) / *(histA+i);
- }
- return sum;
-}
-// euclidiean dist function
-double L2_dist(int length, double* histA, double* histB){
- double sum = 0;
- for(int i=0; i<length;i++){
- double diff = *(histB+i) - *(histA+i);
- sum += (diff * diff);
- }
- return sqrt(sum);
-}
-
-// calc and compare the histograms to the desired
-double ProcessorData::checkHistogram(FullRect rect, cv::Mat thresh_img){
- // found horiz histogram
- double hist_lr[HIST_SIZE];
- // step size along left edge
- cv::Point2f delta_left = (rect.ul - rect.bl)*HIST_SIZE_F;
- // step size along right edge
- cv::Point2f delta_right = (rect.ur - rect.br)*HIST_SIZE_F;
- // sum each left to right line for the histogram
- for(int i=0; i<HIST_SIZE; i++){
- hist_lr[i] = calcHistComponent(rect.bl+i*delta_left,
- rect.br+i*delta_right,thresh_img);
- }
- double check_vert = L2_dist(HIST_SIZE, vert_hist, hist_lr);
- // found vert histogram
- double hist_ub[HIST_SIZE];
- // step size along bottom edge
- cv::Point2f delta_bottom = (rect.bl - rect.br)*HIST_SIZE_F;
- // step size along top edge
- cv::Point2f delta_top = (rect.ul - rect.ur)*HIST_SIZE_F;
- // sum each top to bottom line for the histogram
- for(int i=0; i<HIST_SIZE; i++){
- hist_ub[i] = calcHistComponent(rect.ur+i*delta_top,
- rect.br+i*delta_bottom,thresh_img);
- }
- double check_horz = L2_dist(HIST_SIZE, horz_hist, hist_ub);
-
- // average the two distances
- double check = (check_vert + check_horz)/2.0;
- return check;
-}
-
-// return smallest
-template<class T> inline T Min3(T x, T y, T z) {
- return y <= z ? (x <= y ? x : y)
- : (x <= z ? x : z);
-}
-
-// return largest
-template<class T> inline T Max3(T x, T y, T z) {
- return y >= z ? (x >= y ? x : y)
- : (x >= z ? x : z);
-}
-
-// transforms the contour
-void makeConvex(std::vector<cv::Point> *contour){
- std::vector<cv::Point2i> hull;
- convexHull(*contour, hull, false);
- *contour = hull;
-}
-
-// basic init
-ProcessorData::ProcessorData(int width, int height, bool is_90_) {
- is_90 = is_90_;
- // series b images from nasa
- h1=79; s1=53; v1=82;
- h2=200; s2=255; v2=255;
- // For images from Jerry
- //h1=79; s1=0; v1=11;
- //h2=160; s2=255; v2=255;
- img_width = width;
- img_height = height;
- buffer_size = img_height * img_width * 3;
-#if LOCAL_DEBUG
- global_display = cvCreateImage(cvSize(width, height),
- IPL_DEPTH_8U, 3);
-#endif
- grey_image = cvCreateImage(cvSize(width, height),
- IPL_DEPTH_8U, 1);
- grey_mat = new cv::Mat(grey_image);
-
- // calculate a desired histogram before we start
- int j = 0;
- for(double i=0; j<HIST_SIZE; i+=HIST_SIZE_F){
- if (is_90) {
- if(i < 2.0/12.0 || i > (1.0-2.0/12.0) ) horz_hist[j] = 1;
- else horz_hist[j] = 0.10;
- if(i < 2.0/24.0 || i > (1.0-2.0/24.0) ) vert_hist[j] = 1;
- else vert_hist[j] = 4.0/24.0;
- } else {
- if(i < 2.0/12.0 || i > (1.0-2.0/12.0) ) vert_hist[j] = 1;
- else vert_hist[j] = 0.10;
- if(i < 2.0/24.0 || i > (1.0-2.0/24.0) ) horz_hist[j] = 1;
- else horz_hist[j] = 4.0/24.0;
- }
- j++;
- }
-
- src_header_image = cvCreateImage(cvSize(width, height),
- IPL_DEPTH_8U, 3);
-}
-
-// throw stuff away
-ProcessorData::~ProcessorData() {
- cvReleaseImage(&grey_image);
- cvReleaseImage(&src_header_image);
- delete(grey_mat);
-}
-
-// reset processor data freeing as little as possible.
-void ProcessorData::clear() {
- target_list.clear();
- contour_pairs.clear();
- hierarchy.clear();
-}
-
-
-// r,g,b values are from 0 to 255
-// h = [0,255], s = [0,255], v = [0,255]
-// if s == 0, then h = 0 (undefined)
-void ProcessorData::RGBtoHSV(uchar r, uchar g, uchar b,
- uchar *h, uchar *s, uchar *v ) {
- uchar min, max, delta;
- min = Min3( r, g, b );
- max = Max3( r, g, b );
- *v = max;
- delta = max - min;
- if (max == 0 || delta == 0) {
- *s = 0;
- *h = 0;
- return;
- }
- *s = (255 * long(delta))/max;
- if (max == r) {
- *h = 0 + 43*(g - b)/(delta);
- } else if (max == g) {
- *h = 85 + 43*(b - r)/(delta);
- } else {
- *h = 171 + 43*(r - g)/(delta);
- }
-}
-
-// keep anything that is in our HVS wedge
-// by far the longest running function in this code
-void ProcessorData::threshold(uchar* buffer) {
-#if LOCAL_DEBUG
- uchar * draw_buffer = (uchar *) global_display->imageData;
-#endif
- for (int i = 0, j = 0; i < (buffer_size); i+= 3, j++) {
- uchar r = buffer[i + 2];
- uchar g = buffer[i + 1];
- uchar b = buffer[i + 0];
- uchar h, s, v;
-
- RGBtoHSV(r, g, b, &h, &s, &v);
-
- if (g > 128) {
-#if LOCAL_DEBUG
- draw_buffer[i + 0] = 120;
- draw_buffer[i + 1] = 80;
- draw_buffer[i + 2] = 70;
-#endif
- grey_image->imageData[j] = 255;
- } else if (h == 0 && s == 0 && v >= v1 && v <= v2) {
- // Value thresholds invalid pixels.
-#if LOCAL_DEBUG
- draw_buffer[i + 0] = 200;
- draw_buffer[i + 1] = 50;
- draw_buffer[i + 2] = 100;
-#endif
- grey_image->imageData[j] = 255;
- } else if (h >= h1 && h <= h2 && v >= v1 &&
- v <= v2 && s >= s1 && s <= s2){
- // HSV Thresholded image.
-#if LOCAL_DEBUG
- draw_buffer[i + 0] = 255;
- draw_buffer[i + 1] = 0;
- draw_buffer[i + 2] = 0;
-#endif
- grey_image->imageData[j] = 255;
- } else {
- // Display the unmodified image.
-#if LOCAL_DEBUG
- draw_buffer[i + 0] = buffer[i + 0];
- draw_buffer[i + 1] = buffer[i + 1];
- draw_buffer[i + 2] = buffer[i + 2];
-#endif
- grey_image->imageData[j] = 0;
- }
-
- }
-
-}
-
-// run find contours and try to make them squares
-void ProcessorData::getContours() {
- std::vector<std::vector<cv::Point> > raw_contours;
- //cv::findContours(*grey_mat, raw_contours, hierarchy, CV_RETR_LIST,
- // CV_CHAIN_APPROX_SIMPLE);
- cv::findContours(*grey_mat, raw_contours, hierarchy, CV_RETR_EXTERNAL,
- CV_CHAIN_APPROX_SIMPLE);
-#if LOCAL_DEBUG
- cv::Mat global_mat(global_display);
- cv::Scalar color(255,0,0);
- drawContours(global_mat,raw_contours,-1,color,1);
-
- std::vector<std::vector<cv::Point> > p_contours;
-#endif
- if (!raw_contours.empty()) {
- std::vector<std::vector<cv::Point2i> >::iterator contour_it;
- for (contour_it=raw_contours.begin();
- contour_it != raw_contours.end();
- contour_it++) {
- // make the contours convex
- makeConvex(&(*contour_it));
- std::vector<cv::Point> contour;
- //then make them rectangle
- approxPolyDP(*contour_it, contour, 9, true);
- // stick the raw and processed contours together
- std::pair<std::vector<cv::Point>,
- std::vector<cv::Point> > a_pair(
- *contour_it, contour);
-#if LOCAL_DEBUG
- p_contours.push_back(contour);
-#endif
- // and put them in a list
- contour_pairs.push_back(a_pair);
- }
- }
-#if LOCAL_DEBUG
- cv::Scalar color2(0,0,255);
- drawContours(global_mat,p_contours,-1,color2,CV_FILLED);
-#endif
-}
-
-// filter the contours down to a list of targets
-void ProcessorData::filterToTargets() {
- std::vector<std::pair<
- std::vector<cv::Point>,
- std::vector<cv::Point> > >::iterator contour_it;
- for(contour_it=contour_pairs.begin();
- contour_it != contour_pairs.end();
- contour_it++){
- double check = 0;
- std::vector<cv::Point> raw_contour = std::get<0>(*contour_it);
- std::vector<cv::Point> contour = std::get<1>(*contour_it);
- FullRect rect = calcFullRect(&contour);
- if(contour.size() == 4 &&
- cullObvious(rect, contourArea(contour)) &&
- (check = checkHistogram(rect, *grey_mat)) <= HIST_MATCH){
- // now we have a target, try to improve the square
-#if LOCAL_DEBUG
- /* printf("________\n");
- printf("\tcont= %d raw= %d\n",
- (int)contour.size(), (int)raw_contour.size());
- std::vector<cv::Point2i>::iterator point_it;
- for(point_it=raw_contour.begin();
- point_it != raw_contour.end(); point_it++){
- printf("(%d,%d)", point_it->x, point_it->y);
- }
- printf("\n");*/
-#endif
- target_list.push_back(Target(contour,
- raw_contour, rect, check, is_90));
- }
- if (contour.size() == 4 && cullObvious(rect, contourArea(contour))) {
- LOG(DEBUG, "check= %.2f\n", check);
- }
- }
-}
-
diff --git a/vision/CameraProcessor.h b/vision/CameraProcessor.h
deleted file mode 100644
index 096defb..0000000
--- a/vision/CameraProcessor.h
+++ /dev/null
@@ -1,88 +0,0 @@
-#ifndef VISION_CAMERA_PROCESSOR_H_
-#define VISION_CAMERA_PROCESSOR_H_
-
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <utility>
-#include <vector>
-
-#include "opencv2/imgproc/imgproc.hpp"
-
-// an over described geometric representation of a rectangle
-class FullRect {
- public:
- FullRect();
- cv::Point2f ur; // upper right
- cv::Point2f ul; // upper left
- cv::Point2f br; // bottom right
- cv::Point2f bl; // bottom_left
- cv::Point2f centroid; //centroid
-};
-
-// All data needed once a target is found
-class Target {
- public:
- Target(std::vector<cv::Point> new_contour,
- std::vector<cv::Point> new_raw_contour,
- FullRect new_rect, int new_weight, bool _is_90);
- void refineTarget();
- double getHeight(bool is_90);
- FullRect rect; // geometric representation of the target
- std::vector<cv::Point> this_contour; // opencv contour of target
- std::vector<cv::Point> raw_contour; // opencv contour of target
- double height; // top target to robot
- double weight; // confidence in this target
-};
-
-// main class for processing image data. All relavent data should be
-// accessible through this structure.
-class ProcessorData {
- public:
- ProcessorData(int width, int height, bool is_90_);
- ~ProcessorData();
- void RGBtoHSV(uchar r, uchar g, uchar b,
- uchar *h, uchar *s, uchar *v);
- void threshold(uchar* buffer);
- void getContours();
- void filterToTargets();
- void clear();
- //protected:
- int img_width; // all images should be this width
- int img_height; // and this height
- bool is_90;
- int buffer_size; // width * height * 3
- IplImage *grey_image; // thresholded image
- cv::Mat *grey_mat; // Matrix representaion (just a header)
- std::vector<std::pair<std::vector<cv::Point>,
- std::vector<cv::Point> > > contour_pairs;
- //std::vector<std::vector<cv::Point> > contours; // filtered contours
- //yystd::vector<std::vector<cv::Point> > raw_contours; //original contours
- std::vector<cv::Vec4i> hierarchy; // ordering on contours
- cv::MemStorage g_storage; // opencv storage
- static const int HIST_SIZE = 20; // dimension of histogram
- // ie number of scan lines
- static constexpr double HIST_SIZE_F = 1.0/20.0; // step size
- // should be 1/HIST_SIZE
- double vert_hist[HIST_SIZE]; // desired vertical histogram
- double horz_hist[HIST_SIZE]; // desired horizontal histogram
- // defines the minimum dist for a match
- static constexpr double HIST_MATCH = 1.9;
- double calcHistComponent(
- cv::Point2i start,
- cv::Point2i end,
- cv::Mat thresh_img);
- double checkHistogram(
- FullRect rect,
- cv::Mat thresh_img);
- public:
- int h1, s1, v1, h2, s2, v2; // HSV min and max
- // must be public for tuning
- IplImage * global_display;
-
- IplImage *src_header_image; // header for main image
- std::vector<Target> target_list; // list of found targets
-};
-
-#endif // VISION_CAMERA_PROCESSOR_H_
diff --git a/vision/GoalMaster.cpp b/vision/GoalMaster.cpp
deleted file mode 100644
index 8bf1aba..0000000
--- a/vision/GoalMaster.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-#include "math.h"
-
-#include "aos/common/time.h"
-#include "aos/linux_code/init.h"
-#include "aos/common/logging/logging.h"
-
-#include "frc971/queues/GyroAngle.q.h"
-#include "frc971/queues/CameraTarget.q.h"
-
-#include "vision/RingBuffer.h"
-#include "vision/SensorProcessor.h"
-
-using ::frc971::vision::RingBuffer;
-using ::frc971::sensors::gyro;
-using ::frc971::vision::targets;
-using ::frc971::vision::target_angle;
-using ::frc971::kPixelsToMeters;
-using ::frc971::kMetersToShooterSpeeds;
-using ::frc971::kMetersToShooterAngles;
-using ::frc971::interpolate;
-
-int main() {
- //RingBuffer< ::aos::time::Time, double> buff;
- ::aos::InitNRT();
- while (true) {
- //gyro.FetchNextBlocking();
- //buff.Sample(gyro->sent_time, gyro->angle);
- if (targets.FetchNext()) {
- /*::aos::time::Time stamp = ::aos::time::Time::InNS(targets->timestamp);
- double angle_goal =
- buff.ValueAt(stamp) -
- M_PI / 2.0 * targets->percent_azimuth_off_center / 2.0;
- printf("%g ",angle_goal);
- printf("%g\n",gyro->angle);*/
-
- double meters = interpolate(
- sizeof(kPixelsToMeters) / sizeof(kPixelsToMeters[0]),
- kPixelsToMeters,
- targets->percent_elevation_off_center);
- const double shooter_speed = interpolate(
- sizeof(kMetersToShooterSpeeds) / sizeof(kMetersToShooterSpeeds[0]),
- kMetersToShooterSpeeds,
- meters);
- const double shooter_angle = interpolate(
- sizeof(kMetersToShooterAngles) / sizeof(kMetersToShooterAngles[0]),
- kMetersToShooterAngles,
- meters);
-
- LOG(DEBUG, "%+f=> think target is %f meters away Speed %f Angle %f\n",
- targets->percent_elevation_off_center,
- meters, shooter_speed, shooter_angle);
-
- target_angle.MakeWithBuilder()
- /*.target_angle(angle_goal)*/
- .shooter_speed(shooter_speed)
- .shooter_angle(shooter_angle)
- .Send();
- }
- }
- ::aos::Cleanup();
-}
diff --git a/vision/JPEGRoutines.cpp b/vision/JPEGRoutines.cpp
deleted file mode 100644
index e3dc254..0000000
--- a/vision/JPEGRoutines.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-#include "vision/JPEGRoutines.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include <string.h>
-
-#include "aos/common/time.h"
-
-#include "vision/OpenCVWorkTask.h"
-
-namespace frc971 {
-namespace vision {
-
-/* This is also adapted from libjpeg to be used on decompression tables rather than
- * compression tables as it was origionally intended
- */
-void decompress_add_huff_table (j_decompress_ptr cinfo,
- JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
-/* Define a Huffman table */
-{
- int nsymbols, len;
-
- if (*htblptr == NULL)
- *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
-
- /* Copy the number-of-symbols-of-each-code-length counts */
- memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits));
-
- /* Validate the counts. We do this here mainly so we can copy the right
- * number of symbols from the val[] array, without risking marching off
- * the end of memory. jchuff.c will do a more thorough test later.
- */
- nsymbols = 0;
- for (len = 1; len <= 16; len++)
- nsymbols += bits[len];
- if (nsymbols < 1 || nsymbols > 256){
- fprintf(stderr,"%s:%d: Error, bad huffman table",__FILE__,__LINE__);
- exit(-1);
- }
-
- memcpy((*htblptr)->huffval, val, nsymbols * sizeof(uint8_t));
-
-}
-
-/* standard_huff_tables is taken from libjpeg compression stuff
- * and is here used to set up the same tables in the decompression structure.
- */
-void standard_huff_tables (j_decompress_ptr cinfo)
- /* Set up the standard Huffman tables (cf. JPEG standard section K.3) */
- /* IMPORTANT: these are only valid for 8-bit data precision! */
-{
- static const UINT8 bits_dc_luminance[17] =
- { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
- static const UINT8 val_dc_luminance[] =
- { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
-
- static const UINT8 bits_dc_chrominance[17] =
- { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
- static const UINT8 val_dc_chrominance[] =
- { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
-
- static const UINT8 bits_ac_luminance[17] =
- { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
- static const UINT8 val_ac_luminance[] =
- { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
- 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
- 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
- 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
- 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
- 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
- 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
- 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
- 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
- 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
- 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
- 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
- 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
- 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
- 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
- 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
- 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
- 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
- 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
- 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
- 0xf9, 0xfa };
-
- static const UINT8 bits_ac_chrominance[17] =
- { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
- static const UINT8 val_ac_chrominance[] =
- { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
- 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
- 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
- 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
- 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
- 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
- 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
- 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
- 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
- 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
- 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
- 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
- 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
- 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
- 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
- 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
- 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
- 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
- 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
- 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
- 0xf9, 0xfa };
-
- decompress_add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
- bits_dc_luminance, val_dc_luminance);
- decompress_add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
- bits_ac_luminance, val_ac_luminance);
- decompress_add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
- bits_dc_chrominance, val_dc_chrominance);
- decompress_add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
- bits_ac_chrominance, val_ac_chrominance);
-}
-
-
-
-
-void process_jpeg(unsigned char *out,unsigned char *image,size_t size){
- struct jpeg_decompress_struct cinfo;
- struct jpeg_error_mgr jerr;
-
- static aos::time::Time timestamp_old = aos::time::Time::Now();
- //aos::time::Time timestamp_start = aos::time::Time::Now();
-
- cinfo.err = jpeg_std_error( &jerr );
- cinfo.out_color_space = JCS_RGB;
- jpeg_create_decompress( &cinfo );
- //jpeg_stdio_src( &cinfo, infile );
- jpeg_mem_src(&cinfo,image,size);
-
- jpeg_read_header( &cinfo, TRUE );
- standard_huff_tables (&cinfo);
-
-
-// printf( "JPEG File Information: \n" );
-// printf( "Image width and height: %d pixels and %d pixels.\n", cinfo.image_width, cinfo.image_height );
-// printf( "Color components per pixel: %d.\n", cinfo.num_components );
-// printf( "Color space: %d.\n", cinfo.jpeg_color_space );
- //printf("JpegDecompressed\n");
-
- jpeg_start_decompress( &cinfo );
-
- int offset = 0;
- int step = cinfo.num_components * cinfo.image_width;
- unsigned char *buffers[cinfo.image_height];
- for (int i = cinfo.image_height - 1; i >= 0; --i) {
- buffers[i] = &out[offset];
- offset += step;
- }
-
- while( cinfo.output_scanline < cinfo.image_height )
- {
- jpeg_read_scanlines(&cinfo, &buffers[cinfo.output_scanline],
- cinfo.image_height - cinfo.output_scanline);
- }
-
- /* This used to do BGR to RGB conversions inline */
-/*
- for (int i = 0; i < (int)(cinfo.image_height * cinfo.image_width * 3); i+= 3) {
- uint8_t b = out[i + 0];
- uint8_t r = out[i + 2];
- out[i + 0] = r;
- out[i + 2] = b;
- }
-*/
- jpeg_finish_decompress( &cinfo );
- jpeg_destroy_decompress( &cinfo );
-
- aos::time::Time timestamp_end = aos::time::Time::Now();
-
- //double jpeg_part = ((timestamp_end - timestamp_start).nsec()) / 1000000000.0;
- //double longer_part = ((timestamp_end - timestamp_old).nsec()) / 1000000000.0;
-
- //printf("%g %g\n",jpeg_part / longer_part,1.0 / longer_part);
-
- timestamp_old = timestamp_end;
-
-}
-
-} // namespace vision
-} // namespace frc971
-
diff --git a/vision/JPEGRoutines.h b/vision/JPEGRoutines.h
deleted file mode 100644
index c3b8e13..0000000
--- a/vision/JPEGRoutines.h
+++ /dev/null
@@ -1,17 +0,0 @@
-// for jpeglib.h
-#include <stdio.h>
-
-#include "libjpeg/include/jpeglib.h"
-
-namespace frc971 {
-namespace vision {
-
-void decompress_add_huff_table (j_decompress_ptr cinfo,
- JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val);
-
-void standard_huff_tables (j_decompress_ptr cinfo);
-
-void process_jpeg(unsigned char *out,unsigned char *image,size_t size);
-
-} // namespace vision
-} // namespace frc971
diff --git a/vision/OpenCVWorkTask.cpp b/vision/OpenCVWorkTask.cpp
deleted file mode 100644
index 982d670..0000000
--- a/vision/OpenCVWorkTask.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include <string.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-
-#include <vector>
-#include <iostream>
-
-#include "libjpeg/include/jpeglib.h"
-
-#include "aos/common/time.h"
-#include "aos/linux_code/camera/Buffers.h"
-#include "aos/linux_code/init.h"
-#include "aos/common/logging/logging.h"
-
-#include "vision/OpenCVWorkTask.h"
-#include "vision/CameraProcessor.h"
-#include "vision/JPEGRoutines.h"
-
-
-namespace frc971 {
-namespace vision {
-
-} // namespace vision
-} // namespace frc971
-
-namespace {
-void SaveImageToFile(IplImage *image, const char *filename) {
- FILE *file = fopen(filename, "w");
-
- fputs("P3\n320 240\n255\n", file);
- ::cv::Mat img(image);
- for (int i = 0; i < img.rows; i++) {
- for (int j = 0; j < img.cols; j++) {
- // You can now access the pixel value with cv::Vec3b
- fprintf(file, "%d %d %d ",
- img.at<cv::Vec3b>(i,j)[0],
- img.at<cv::Vec3b>(i,j)[1],
- img.at<cv::Vec3b>(i,j)[2]);
-
- }
- fputs("\n", file);
- }
- fclose(file);
-}
-}
-
-#include "frc971/queues/CameraTarget.q.h"
-using frc971::vision::targets;
-
-void sender_main(){
- ::aos::camera::Buffers buffers;
- CvSize size;
- size.width = ::aos::camera::Buffers::Buffers::kWidth;
- size.height = ::aos::camera::Buffers::Buffers::kHeight;
- unsigned char buffer[::aos::camera::Buffers::Buffers::kWidth *
- ::aos::camera::Buffers::Buffers::kHeight * 3];
-
- // create processing object
- ProcessorData processor(size.width, size.height, false);
-
- printf("started sender main\n");
- LOG(INFO, "Camera server started\n");
- while(true){
- //usleep(7500);
- size_t data_size;
- timeval timestamp_timeval;
- LOG(DEBUG, "getting new image\n");
- const void *image = buffers.GetNext(
- true, &data_size, ×tamp_timeval, NULL);
- ::aos::time::Time timestamp(timestamp_timeval);
-
- LOG(DEBUG, "Got new image\n");
- frc971::vision::process_jpeg(
- buffer, static_cast<unsigned char *>(const_cast<void *>(image)),
- data_size);
-
- // build the headers on top of the buffer
- cvSetData(processor.src_header_image,
- buffer,
- ::aos::camera::Buffers::Buffers::kWidth * 3);
-
- // Reset.
- processor.clear();
- // transform the buffer into targets
- processor.threshold(buffer);
-
- processor.getContours();
- processor.filterToTargets();
-
- // could be used for debug ie drawContours
- //std::vector<std::vector<cv::Point> > target_contours;
- //std::vector<std::vector<cv::Point> > best_contours;
- std::vector<Target>::iterator target_it;
- Target *best_target = NULL;
- // run through the targets
- LOG(DEBUG, "Found %u targets\n", processor.target_list.size());
- for(target_it = processor.target_list.begin();
- target_it != processor.target_list.end(); target_it++){
- //target_contours.push_back(*(target_it->this_contour));
- // select the highest target
- if (best_target == NULL) {
- best_target = &*target_it;
- } else {
- if (target_it->height < best_target->height) {
- best_target = &*target_it;
- }
- }
- }
- // if we found one then send it on
- if (best_target != NULL) {
- LOG(DEBUG, "Target is %f\n", best_target->rect.centroid.x);
- targets.MakeWithBuilder()
- .percent_azimuth_off_center(
- best_target->rect.centroid.y / (double)::aos::camera::Buffers::kHeight - 0.5)
- .percent_elevation_off_center(
- best_target->rect.centroid.x / (double)::aos::camera::Buffers::kWidth - 0.5)
- .timestamp(timestamp.ToNSec())
- .Send();
- }
- //static int counter = 0;
- //if (++counter > 2) {
- //break;
- //}
- }
-}
-
-
-int main(int /*argc*/, char** /*argv*/){
- ::aos::InitNRT();
- sender_main();
- ::aos::Cleanup();
-}
-
diff --git a/vision/OpenCVWorkTask.h b/vision/OpenCVWorkTask.h
deleted file mode 100644
index 78bda5d..0000000
--- a/vision/OpenCVWorkTask.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef VISION_OPENCV_WORK_TASK_H_
-#define VISION_OPENCV_WORK_TASK_H_
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include "event2/buffer.h"
-#include "event2/event.h"
-#include "event2/listener.h"
-#include "event2/bufferevent.h"
-
-#include "aos/common/mutex.h"
-
-namespace frc971 {
-namespace vision {
-
-} // namespace vision
-} // namespace frc971
-
-#endif // VISION_OPENCV_WORK_TASK_H_
diff --git a/vision/PacketNotifier.cpp b/vision/PacketNotifier.cpp
deleted file mode 100644
index d12872e..0000000
--- a/vision/PacketNotifier.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-#include "vision/PacketNotifier.h"
-
-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include <string.h>
-
-namespace frc971 {
-namespace vision {
-
-void PacketNotifier::RegisterSender(){
- close(fd[1]);
-}
-void PacketNotifier::RegisterReciever(){
- close(fd[0]);
-}
-PacketNotifier *PacketNotifier::MMap(size_t data_size){
- PacketNotifier *data;
- data = (PacketNotifier *)mmap(NULL, ((data_size * 3 + 4095 + sizeof(PacketNotifier)) / 4096) * 4096,
- PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
- data->data_size = data_size;
- socketpair(PF_LOCAL, SOCK_STREAM, 0, data->fd);
- for(int i = 0;i < 3;i++){
- data->buffs[i] = (uint8_t *)data + (sizeof(PacketNotifier) + i * data_size);
- }
- void *place = &(data->mutex);
- *((int *)place) = 0; // The Mutex class needs a placement new operator. (you know, keep the masses happy);
- data->in_flight = false;
- data->to_send = -1;
- data->sending = -1;
- return data;
-}
-void *PacketNotifier::GetBuffer(){
- mutex.Lock();
- for(int i = 0; i < 3 ; i++){ //search for open spot.
- if(i != sending && i != to_send){ //open
- filling = i;
- mutex.Unlock();
- //printf("leasing out to fill buff # %d\n",i);
- return buffs[i];
- }
- }
- mutex.Unlock();
- //printf("Error in the fabric of the universe\n");
- exit(-42);
-}
-void PacketNotifier::Notify(){
- mutex.Lock();
- to_send = filling;
- filling = -1;
- mutex.Unlock();
- // wall error
- if(write(fd[0],"\n",1)) {}
-}
-
-void PacketNotifier::DataSent(const void * /*data*/, size_t /*datalen*/){
- //printf("packet_sent: %d; fill: %d; to_send: %d \n",sending,filling,to_send);
- mutex.Lock();
- sending = -1;
- mutex.Unlock();
- in_flight = false;
-}
-bool PacketNotifier::GetData(char **place_to_put,size_t *length){
- if(in_flight) return false;
- mutex.Lock();
- *length = data_size;
- *place_to_put = (char *)buffs[to_send];
- sending = to_send;
- to_send = -1;
- mutex.Unlock();
- in_flight = true;
- return true;
-}
-
-} // namespace vision
-} // namespace frc971
-
diff --git a/vision/PacketNotifier.h b/vision/PacketNotifier.h
deleted file mode 100644
index 7aff7fa..0000000
--- a/vision/PacketNotifier.h
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef FRC971_VISION_PACKET_NOTIFIER_H_
-#define FRC971_VISION_PACKET_NOTIFIER_H_
-#include "event2/buffer.h"
-#include "event2/event.h"
-#include "event2/listener.h"
-#include "event2/bufferevent.h"
-#include "aos/common/mutex.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-namespace frc971 {
-namespace vision {
-
-/* This class lives in shared memory (using an anonomous mmap) to transfer data between
- * the server process and the image processing process.
- */
-struct PacketNotifier{
- aos::Mutex mutex;
- int fd[2];
- //3 things can be happening:
- //something waiting to be sent, something sending, and something getting filled (decompressed to)
- void *buffs[3];
- int to_send;
- int filling;
- int sending;
- bool in_flight;
- size_t data_size;
- void Notify();
- void RegisterSender();
- void RegisterReciever();
- int RecieverFD(){ return fd[1]; }
- static PacketNotifier *MMap(size_t data_size);
- void DataSent(const void * /*data*/, size_t /*datalen*/);
- void *GetBuffer();
- static void StaticDataSent(const void *data, size_t datalen, void *self){
- ((PacketNotifier *)(self))->DataSent(data,datalen);
- }
- bool GetData(char **place_to_put,size_t *length);
-};
-} // namespace vision
-} // namespace frc971
-
-
-#endif //FRC971_VISION_PACKET_NOTIFIER_H_
diff --git a/vision/RingBuffer.h b/vision/RingBuffer.h
deleted file mode 100644
index f333f29..0000000
--- a/vision/RingBuffer.h
+++ /dev/null
@@ -1,67 +0,0 @@
-#ifndef VISION_RINGBUFFER_H_
-#define VISION_RINGBUFFER_H_
-
-#include <stdio.h>
-#include <stdlib.h>
-
-namespace frc971 {
-namespace vision {
-
-template<class T,class V>
-class RingBuffer{
- //record class to hold sampes
- class Samples{
- public:
- T time;
- V value;
- };
- Samples *samples;
- int current_;
- int wraps_;
- V value_at(int index){
- return samples[index & 255].value;
- }
- T time_at(int index){
- return samples[index & 255].time;
- }
- public:
- RingBuffer(){
- current_ = 0;
- wraps_ = 0;
- samples = (Samples *)malloc(sizeof(Samples) * 256);
- }
- // Adds samples into the ringbuffer.
- void Sample(T time,V val){
- current_ += 1;
- wraps_ += current_ / 256;
- current_ = current_ % 256;
- samples[current_].time = time;
- samples[current_].value = val;
- }
- // Binary Search to find and interpolate the values.
- V ValueAt(T time){
- int start = current_ - 255;
- int end = current_;
- if(start < 0 && !wraps_){
- start = 0;
- }
- int max = end;
- int min = start;
- while(end - start > 1){
- int mid = (start + end) / 2;
- Samples check = samples[mid & 255];
- if(check.time < time){
- start = mid;
- min = mid;
- }else{
- max = mid;
- end = mid;
- }
- }
- return value_at(min) + (value_at(max) - value_at(min)) *
- ((time - time_at(min)).ToSeconds()/(time_at(max) - time_at(min)).ToSeconds());
- }
-};
-}; // vision
-}; // frc971
-#endif // VISION_RINGBUFFER_H_
diff --git a/vision/SensorProcessor.cpp b/vision/SensorProcessor.cpp
deleted file mode 100644
index 2060956..0000000
--- a/vision/SensorProcessor.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-#include "vision/SensorProcessor.h"
-
-#include <stdio.h>
-
-namespace frc971 {
-
-// give a set of x -> fx pairs find a range for our value
-// then interpolate between and return an interpolated fx.
-// If the value is off the end just extend the line to
-// meet our point. If something does go wrong (and it
-// never should) it will return -1.
-double interpolate(int num_interp_vals,
- const Interpolation *interp, double value) {
- double dy;
- double dx;
- double a;
- double intercept;
- //printf("for val %.1f\n", value);
- if (value < interp[0].x) {
- // if closer than nearest
- dy = interp[1].fx - interp[0].fx;
- dx = interp[1].x - interp[0].x;
- a = value - interp[0].x;
- intercept = interp[0].fx;
- //printf("LESS THAN\n");
- } else if (value > interp[num_interp_vals-1].x){
- // if further than furthest
- dy = interp[num_interp_vals-1].fx - interp[num_interp_vals-2].fx;
- dx = interp[num_interp_vals-1].x - interp[num_interp_vals-2].x;
- a = value - interp[num_interp_vals-2].x;
- intercept = interp[num_interp_vals-2].fx;
- //printf("GT THAN\n");
- } else {
- //printf("gh0\n");
- // scan for range
- for(int i=0; i<num_interp_vals-1; i++){
- if(value >= interp[i].x && value <= interp[i+1].x){
- // printf("(%.1f,%.1f)=(%.1f,%.1f)\n",
- // interp[i].x, interp[i+1].x,
- // interp[i].fx, interp[i+1].fx);
- double lambda =
- (value - interp[i].x)/(interp[i+1].x - interp[i].x);
- return (1-lambda)*interp[i].fx + lambda*interp[i+1].fx;
- }
- }
- // this should maybe be an assert
- return -1;
- }
-
- return ( (dy/dx)*a + intercept );
-}
-
-} // namespace frc971
diff --git a/vision/SensorProcessor.h b/vision/SensorProcessor.h
deleted file mode 100644
index daf24be..0000000
--- a/vision/SensorProcessor.h
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef VISION_SENSOR_PROCESSOR_H_
-#define VISION_SENSOR_PROCESSOR_H_
-
-namespace frc971 {
-
-// struct maps a single point x to to a value f of x
-typedef struct {
- double x;
- double fx;
-} Interpolation;
-
-static const Interpolation kPixelsToMeters[] = {
- {-0.050781, 4.7498},
- {-0.0375, 4.318},
- {0.028125, 3.9878},
- {0.080469, 3.51},
- {0.126563, 3.1496},
- {0.131, 2.9972},
- {0.144, 2.921},
- {0.196, 3.2258},
- // Below here is junk because it starts coming off of the tower base.
- {0.296875, 2.667},
- {0.351562, 2.3876},
-};
-
-// Must be in reverse order in meters.
-static const Interpolation kMetersToShooterSpeeds[] = {
- {2.0, 375.0},
- {3.0, 360.0},
- {4.5, 375.0},
-};
-
-static const Interpolation kMetersToShooterAngles[] = {
- {3.0, 0.68},
- {3.7, 0.635},
- {4.15, 0.58},
- {5.0, 0.51},
-};
-
-double interpolate(int num_interp_vals,
- const Interpolation *interp, double value);
-
-} // namespace frc971
-
-#endif // VISION_SENSOR_PROCESSOR_H_
diff --git a/vision/bmp_stream/bmp.rb b/vision/bmp_stream/bmp.rb
deleted file mode 100644
index 122c9de..0000000
--- a/vision/bmp_stream/bmp.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-class BMPHeader
- def initialize(width,height)
- @width = width
- @height = height
- end
- def text()
- size = @width * @height * 3
- return ["BM",size + 54,"\0\0\0\0",54,40,@width,
- @height,1,24,0,size,2835,2835,0,0].pack("a2Ia4IIIIssIIIIII")
- end
-end
diff --git a/vision/bmp_stream/bmp_dump.rb b/vision/bmp_stream/bmp_dump.rb
deleted file mode 100644
index 6c5133c..0000000
--- a/vision/bmp_stream/bmp_dump.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-require "socket"
-
-require "bmp"
-sock = TCPSocket.new(ARGV[0] || "fitpc",8020)
-$width = 640 / 2
-$height = 480 / 2
-$header = BMPHeader.new($width,$height).text()
-
-
-
-require "rubygems"
-require "gtk2"
-
-
-$image = Gtk::Image.new()
-$window = Gtk::Window.new()
-$window.add($image)
-$window.show_all()
-$window.signal_connect("delete-event") { Gtk.main_quit}
-
-loader = Gdk::PixbufLoader.new
-loader.write($header)
-data = sock.read($width * $height * 3)
-loader.last_write(data)
-loader.close
-$image.pixbuf = loader.pixbuf
-$oldtime = Time.now
-i = 0
-Gtk.idle_add do
- loader = Gdk::PixbufLoader.new
- loader.write($header)
- data = sock.read($width * $height * 3)
-# (640 * 480).times do |i| #BGR -> RGB
-# b,g,r = data[i * 3 + 0],data[i * 3 + 1],data[i * 3 + 2]
-# data[i * 3 + 0],data[i * 3 + 1],data[i * 3 + 2] = r,g,b
-# end
- loader.last_write(data)
- loader.close
- new_time = Time.now()
- puts 1 / (new_time - $oldtime)
- $oldtime = new_time
- $image.pixbuf = loader.pixbuf
-end
-
-Gtk.main()
diff --git a/vision/bmp_stream/bmp_stream_from_file.rb b/vision/bmp_stream/bmp_stream_from_file.rb
deleted file mode 100644
index 3324484..0000000
--- a/vision/bmp_stream/bmp_stream_from_file.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-require "socket"
-$header = File.open("header.bmp") { |f| f.read(54)}
-
-
-sock = File.open("output.bmp_stream")
-#TCPSocket.new(ARGV[0] || "fitpc",8020)
-
-
-
-require "rubygems"
-require "gtk2"
-
-
-$image = Gtk::Image.new()
-$window = Gtk::Window.new()
-$window.add($image)
-$window.show_all()
-$window.signal_connect("delete-event") { Gtk.main_quit}
-
-loader = Gdk::PixbufLoader.new
-loader.write($header)
-data = sock.read(320 * 240 * 3)
-loader.last_write(data)
-loader.close
-$image.pixbuf = loader.pixbuf
-$oldtime = Time.now
-Gtk.timeout_add(1000) do
- loader = Gdk::PixbufLoader.new
- loader.write($header)
- data = sock.read(320 * 240 * 3)
-# (640 * 480).times do |i| #BGR -> RGB
-# b,g,r = data[i * 3 + 0],data[i * 3 + 1],data[i * 3 + 2]
-# data[i * 3 + 0],data[i * 3 + 1],data[i * 3 + 2] = r,g,b
-# end
- loader.last_write(data)
- loader.close
- new_time = Time.now()
- puts 1.0 / (new_time - $oldtime)
- $oldtime = new_time
- $image.pixbuf = loader.pixbuf
-end
-
-Gtk.main()
diff --git a/vision/bmp_stream/bmp_stream_to_file.rb b/vision/bmp_stream/bmp_stream_to_file.rb
deleted file mode 100644
index 962bb2d..0000000
--- a/vision/bmp_stream/bmp_stream_to_file.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require "socket"
-$header = File.open("header.bmp") { |f| f.read(54)}
-
-
-sock = TCPSocket.new(ARGV[0] || "fitpc",8020)
-
-
-
-require "rubygems"
-require "gtk2"
-
-
-
-File.open("output.bmp_stream","w+") do |file|
- 400.times do |i|
- data = sock.read(320 * 240 * 3)
- file.print(data)
- puts "frame: #{i}"
- end
-end
diff --git a/vision/tests/FieldDBGCamProc.cpp b/vision/tests/FieldDBGCamProc.cpp
deleted file mode 100644
index f23b541..0000000
--- a/vision/tests/FieldDBGCamProc.cpp
+++ /dev/null
@@ -1,210 +0,0 @@
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <vector>
-
-#include "../CameraProcessor.h"
-#include "../SensorProcessor.h"
-
-#include "opencv2/highgui/highgui.hpp"
-
-const int num_names = 39;
-
-
-static const bool USE_ROTATED = true;
-static const int use_width = 320;
-static const int use_height = 240;
-const char * image_names[num_names] = {
- "NASA_bmp/img26_series_b_side_204_e65.jpg",
- "NASA_bmp/img19_series_b_side_110_e65.jpg",
- "NASA_bmp/img12_series_b_center_224_e65.jpg",
- "NASA_bmp/img23_series_b_side_101_e65.jpg",
- "NASA_bmp/img15_series_b_side_230_e65.jpg",
- "NASA_bmp/img10_series_b_center_203_e65.jpg",
- "NASA_bmp/img11_series_b_center_203_e65.jpg",
- "NASA_bmp/img13_series_b_center_260_e65.jpg",
- "NASA_bmp/img14_series_b_center_251_e65.jpg",
- "NASA_bmp/img16_series_b_side_196_e65.jpg",
- "NASA_bmp/img17_series_b_side_160_e65.jpg",
- "NASA_bmp/img18_series_b_side_140_e65.jpg",
- "NASA_bmp/img1_center_200_e65.jpg",
- "NASA_bmp/img20_series_b_side_114_e65.jpg",
- "NASA_bmp/img21_series_b_side_137_e65.jpg",
- "NASA_bmp/img22_center field_e10.jpg",
- "NASA_bmp/img22_dog Center Field_e10.jpg",
- "NASA_bmp/img22_series_b_side_150_e65.jpg",
- "NASA_bmp/img23_center field_e10.jpg",
- "NASA_bmp/img24_center field_e10.jpg",
- "NASA_bmp/img24_series_b_side_104_e65.jpg",
- "NASA_bmp/img25_series_b_side_195_e65.jpg",
- "NASA_bmp/img27_series_b_side_192_e65.jpg",
- "NASA_bmp/img28_series_b_side_192_e65.jpg",
- "NASA_bmp/img29_series_b_side_186_e65.jpg",
- "NASA_bmp/img2_center_207_e65.jpg",
- "NASA_bmp/img30_series_b_side_177_e65.jpg",
- "NASA_bmp/img31_series_b_side_176_e65.jpg",
- "NASA_bmp/img32_series_b_side_212_e65.jpg",
- "NASA_bmp/img33_series_b_side_251_e65.jpg",
- "NASA_bmp/img34_series_b_side_272_e65.jpg",
- "NASA_bmp/img35_series_b_side_23+219_e65.jpg",
- "NASA_bmp/img3_center_180_e65.jpg",
- "NASA_bmp/img4_series_b_center_106_e65.jpg",
- "NASA_bmp/img5_series_b_center_122_e65.jpg",
- "NASA_bmp/img6_series_b_center_145_e65.jpg",
- "NASA_bmp/img7_series_b_center_174_e65.jpg",
- "NASA_bmp/img8_series_b_center_196_e65.jpg",
- "NASA_bmp/img9_series_b_center_201_e65.jpg"};
-
-const char * WINDOW_NAME = "Treshhold Window";
-const char * WINDOW_NAME2 = "Target Window";
-
-
-static void onMouse( int event, int x, int y, int, void* userData ) {
- if( event != CV_EVENT_LBUTTONDOWN ) return;
- ProcessorData *proc = (ProcessorData *) userData;
- IplImage *image = proc->src_header_image;
- uchar b = *((uchar*) (image->imageData + y*image->widthStep + 3*x));
- uchar g = *((uchar*) (image->imageData + y*image->widthStep + 3*(x+1)));
- uchar r = *((uchar*) (image->imageData + y*image->widthStep + 3*(x+2)));
-
- uchar h=0;
- uchar s=0;
- uchar v=0;
- proc->RGBtoHSV(r, g, b, &h, &s, &v);
-
-
- *((uchar*) (image->imageData + y*image->widthStep + 3*x)) = 128;
- *((uchar*) (image->imageData + y*image->widthStep + 3*(x+1))) = 128;
- *((uchar*) (image->imageData + y*image->widthStep + 3*(x+2))) = 255;
-
- cv::Mat src(image);
- //cv::imshow("test", src);
-
- printf("got click (%d,%d)= <%d,%d,%d> -- [%d,%d,%d]\n",
- x, y, r, g, b, h, s, v);
-}
-
-
-int main( int argc, char *argv[] ){
- ProcessorData processor(use_width, use_height, USE_ROTATED);
- int img_cycle = 0;
- int thresh = 100;
-
- cvStartWindowThread();
-
- cvNamedWindow ("cnt", CV_WINDOW_AUTOSIZE);
- cvNamedWindow ("GLOBAL", CV_WINDOW_AUTOSIZE);
- //cvNamedWindow ("Grey Img", CV_WINDOW_AUTOSIZE);
- //cvNamedWindow ("test", CV_WINDOW_AUTOSIZE);
- cvNamedWindow (WINDOW_NAME2, CV_WINDOW_AUTOSIZE);
- cvNamedWindow (WINDOW_NAME, CV_WINDOW_AUTOSIZE);
-
- cvMoveWindow(WINDOW_NAME,0,0);
- cvMoveWindow("GLOBAL",325,0);
- cvMoveWindow(WINDOW_NAME2,650,0);
- //cvMoveWindow("Grey Img", 0, 275);
- //cvMoveWindow("test", 325, 275);
- cvMoveWindow("cnt",1100,100);
- //Creating the trackbars
- cvCreateTrackbar("H1","cnt",&processor.h1,360,0);
- cvCreateTrackbar("H2","cnt",&processor.h2,360,0);
- cvCreateTrackbar("S1","cnt",&processor.s1,255,0);
- cvCreateTrackbar("S2","cnt",&processor.s2,255,0);
- cvCreateTrackbar("V1","cnt",&processor.v1,255,0);
- cvCreateTrackbar("V2","cnt",&processor.v2,255,0);
-
- while (img_cycle >= 0) {
- processor.clear();
- printf("%d = %s\n", img_cycle, image_names[img_cycle]);
- processor.src_header_image = cvLoadImage(image_names[img_cycle]);
- cvCopy(processor.src_header_image, processor.global_display);
-
- cv::setMouseCallback( WINDOW_NAME2, onMouse,
- (void *)&processor );
-
- cv::Mat global_mat(processor.global_display);
- cv::Mat src_mat(processor.src_header_image);
-
- // These lines are the vision processing, the rest of main
- // is just fluff
- processor.threshold((uchar *)
- processor.src_header_image->imageData);
- processor.getContours();
- processor.filterToTargets();
-
- if(!processor.target_list.empty()){
- std::vector<std::vector<cv::Point> > target_contours;
- std::vector<std::vector<cv::Point> > best_contours;
- std::vector<std::vector<cv::Point> > raw_contours;
- std::vector<Target>::iterator target_it;
- Target *best_target = NULL;
- int i = 0;
- for(target_it = processor.target_list.begin();
- target_it != processor.target_list.end(); target_it++){
- target_contours.push_back(target_it->this_contour);
- raw_contours.push_back(target_it->raw_contour);
- printf("%d: h=%.1f, interp=%.1f, <x,y>=<%.1f,%.1f>\n",
- i++, target_it->height,
- interpolate(4, &pixel_to_dist[0], target_it->rect.centroid.x),
- target_it->rect.centroid.x, target_it->rect.centroid.y);
- if (best_target == NULL) {
- best_target = &*target_it;
- } else {
- if (target_it->height > best_target->height) {
- best_target = &*target_it;
- }
- /* if (processor.is_90) {
- if (target_it->rect.centroid.x > best_target->rect.centroid.x) {
- best_target = &*target_it;
- }
- } else {
- if (target_it->rect.centroid.y < best_target->rect.centroid.y) {
- best_target = &*target_it;
- }
- }*/
- }
- }
- best_contours.push_back(best_target->this_contour);
- //drawContours(global_mat,target_contours,-1,color,CV_FILLED);
- cv::imshow(WINDOW_NAME, src_mat);
- //cv::imshow("Grey Img", *processor.grey_mat);
- cv::Scalar color(0,0,255);
- cv::drawContours( src_mat, target_contours, -1, color, CV_FILLED );
- cv::Scalar color2(128,0,255);
- cv::drawContours( src_mat, best_contours, -1, color2, CV_FILLED );
- cv::Scalar color3(0,255,0);
- cv::drawContours( src_mat, raw_contours, -1, color3, 1 );
- }
- //cv::Mat grey_mat(grey_image);
- //cv::imshow(WINDOW_NAME2, grey_mat);
- cv::imshow("GLOBAL", global_mat);
- cv::imshow(WINDOW_NAME2, src_mat);
- char key = cvWaitKey(3000);
- switch (key) {
- case ' ':
- img_cycle++;
- img_cycle = img_cycle % num_names;
- printf("%c %d= %s\n", key, img_cycle, image_names[img_cycle]);
- break;
- case 'g':
- thresh++;
- thresh = (thresh % 255);
- printf("+ thresh= %d\n", thresh);
- break;
- case 'G':
- thresh--;
- thresh = (thresh % 255);
- printf("- thresh= %d\n", thresh);
- break;
- case 'q':
- img_cycle = -1;
- break;
- default:
- break;
- }
- //redraw image cuz we drew all over it
- }
-
- cvDestroyWindow(WINDOW_NAME);
-}
-
diff --git a/vision/vision.gyp b/vision/vision.gyp
deleted file mode 100644
index 81e5562..0000000
--- a/vision/vision.gyp
+++ /dev/null
@@ -1,38 +0,0 @@
-{
- 'targets': [
- {
- 'target_name': 'OpenCVWorkTask',
- 'type': 'executable',
- 'sources': [
- 'OpenCVWorkTask.cpp',
- 'CameraProcessor.cpp',
- #'BinaryServer.cpp',
- #'PacketNotifier.cpp',
- 'JPEGRoutines.cpp',
- ],
- 'dependencies': [
- '<(AOS)/linux_code/linux_code.gyp:init',
- '<(AOS)/common/common.gyp:time',
- '<(EXTERNALS):libevent',
- '<(EXTERNALS):libjpeg',
- '<(EXTERNALS):opencv',
- '<(AOS)/linux_code/camera/camera.gyp:buffers',
- '<(DEPTH)/frc971/queues/queues.gyp:queues',
- ],
- },
- {
- 'target_name': 'GoalMaster',
- 'type': 'executable',
- 'sources': [
- 'GoalMaster.cpp',
- 'SensorProcessor.cpp',
- ],
- 'dependencies': [
- '<(AOS)/linux_code/linux_code.gyp:init',
- '<(AOS)/common/common.gyp:time',
- '<(DEPTH)/frc971/queues/queues.gyp:queues',
- '<(AOS)/build/aos.gyp:logging',
- ],
- },
- ],
-}