got vision code actually working (and somewhat tuned) but it crashes
diff --git a/vision/OpenCVWorkTask.cpp b/vision/OpenCVWorkTask.cpp
index 9d68065..f17803e 100644
--- a/vision/OpenCVWorkTask.cpp
+++ b/vision/OpenCVWorkTask.cpp
@@ -4,11 +4,13 @@
#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 <vector>
+#include <iostream>
+
#include "aos/common/time.h"
#include "aos/atom_code/camera/Buffers.h"
#include "aos/externals/libjpeg/include/jpeglib.h"
@@ -17,8 +19,6 @@
#include "vision/OpenCVWorkTask.h"
#include "vision/CameraProcessor.h"
-#include "vision/BinaryServer.h"
-#include "vision/PacketNotifier.h"
#include "vision/JPEGRoutines.h"
@@ -28,10 +28,6 @@
} // namespace vision
} // namespace frc971
-void reciever_main(frc971::vision::PacketNotifier *notify){
- frc971::vision::BinaryServer test(8020,notify);
-}
-
namespace {
void SaveImageToFile(IplImage *image, const char *filename) {
FILE *file = fopen(filename, "w");
@@ -56,13 +52,13 @@
#include "frc971/queues/CameraTarget.q.h"
using frc971::vision::targets;
-#include <iostream>
-void sender_main(frc971::vision::PacketNotifier *notify){
- ::aos::InitNRT();
+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);
@@ -73,17 +69,15 @@
//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);
- //TODO(pschuh): find proper way to cast away const for this: :(
- // parker you prolly want const_cast<type>(var);
- LOG(INFO, "Got new image\n");
- unsigned char *buffer = (unsigned char *)notify->GetBuffer();
- frc971::vision::process_jpeg(buffer,
- (unsigned char *)const_cast<void *>(image),
- data_size);
+ 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,
@@ -104,7 +98,7 @@
std::vector<Target>::iterator target_it;
Target *best_target = NULL;
// run through the targets
- LOG(INFO, "Found %u targets\n", processor.target_list.size());
+ 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));
@@ -119,7 +113,7 @@
}
// if we found one then send it on
if (best_target != NULL) {
- LOG(INFO, "Target is %f\n", best_target->rect.centroid.x);
+ 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)
@@ -128,29 +122,17 @@
.timestamp(timestamp.ToNSec())
.Send();
}
- notify->Notify();
//static int counter = 0;
//if (++counter > 2) {
//break;
//}
}
- ::aos::Cleanup();
}
int main(int /*argc*/, char** /*argv*/){
- frc971::vision::PacketNotifier *notify = frc971::vision::PacketNotifier::MMap(
- ::aos::camera::Buffers::kHeight * ::aos::camera::Buffers::kWidth * 3);
- pid_t pid = fork();
- if(pid < 0){
- fprintf(stderr,"%s:%d: Error in fork()\n",__FILE__,__LINE__);
- }
- if(pid == 0){
- notify->RegisterSender();
- sender_main(notify);
- }else{
- notify->RegisterReciever();
- reciever_main(notify);
- }
+ ::aos::InitNRT();
+ sender_main();
+ ::aos::Cleanup();
}