diff --git a/conf/modules/cv_opticflow.xml b/conf/modules/cv_opticflow.xml index 5174c7a7a3..4928d81dbf 100644 --- a/conf/modules/cv_opticflow.xml +++ b/conf/modules/cv_opticflow.xml @@ -82,7 +82,26 @@ + + + include $(CFG_SHARED)/udp.makefile + + VIEWVIDEO_HOST ?= $(MODEM_HOST) + VIEWVIDEO_PORT_OUT ?= 5000 + VIEWVIDEO_BROADCAST ?= TRUE + VIEWVIDEO_USE_NETCAT ?= FALSE + + VIEWVID_CFLAGS = -DVIEWVIDEO_HOST=$(VIEWVIDEO_HOST) -DVIEWVIDEO_PORT_OUT=$(VIEWVIDEO_PORT_OUT) + ifneq (,$(findstring $(VIEWVIDEO_USE_NETCAT),0 FALSE)) + ap.CFLAGS += $(VIEWVID_CFLAGS) -DVIEWVIDEO_BROADCAST=$(VIEWVIDEO_BROADCAST) + nps.CFLAGS += $(VIEWVID_CFLAGS) -DVIEWVIDEO_BROADCAST=FALSE + else + $(TARGET).CFLAGS += $(VIEWVID_CFLAGS) -DVIEWVIDEO_USE_NETCAT + endif + + + diff --git a/sw/airborne/modules/computer_vision/lib/vision/edge_flow.c b/sw/airborne/modules/computer_vision/lib/vision/edge_flow.c new file mode 100644 index 0000000000..ca66439b54 --- /dev/null +++ b/sw/airborne/modules/computer_vision/lib/vision/edge_flow.c @@ -0,0 +1,14 @@ +/* + * edge_flow.c + * + * Created on: Feb 22, 2016 + * Author: knmcguire + */ +#include + + +void test_function(struct image_t *img,struct image_t *img_gray) +{ + image_to_grayscale(img, img_gray); + +} diff --git a/sw/airborne/modules/computer_vision/lib/vision/edge_flow.h b/sw/airborne/modules/computer_vision/lib/vision/edge_flow.h new file mode 100644 index 0000000000..eb4d4742b4 --- /dev/null +++ b/sw/airborne/modules/computer_vision/lib/vision/edge_flow.h @@ -0,0 +1,19 @@ +/* + * edge_flow.h + * + * Created on: Feb 22, 2016 + * Author: knmcguire + */ + +#ifndef EDGE_FLOW_H_ +#define EDGE_FLOW_H_ + + +#include "std.h" +#include "opticflow/inter_thread_data.h" +#include "lib/vision/image.h" +#include "lib/v4l/v4l2.h" + +void test_function(struct image_t *image,struct image_t *image_gray); + +#endif /* EDGE_FLOW_H_ */ diff --git a/sw/airborne/modules/computer_vision/opticflow_module.c b/sw/airborne/modules/computer_vision/opticflow_module.c index 4363d2cd4c..119fc1861f 100644 --- a/sw/airborne/modules/computer_vision/opticflow_module.c +++ b/sw/airborne/modules/computer_vision/opticflow_module.c @@ -36,6 +36,8 @@ #include "lib/v4l/v4l2.h" #include "lib/encoding/jpeg.h" #include "lib/encoding/rtp.h" +#include "lib/vision/edge_flow.h" + /* Default sonar/agl to use in opticflow visual_estimator */ #ifndef OPTICFLOW_AGL_ID @@ -77,6 +79,8 @@ static pthread_t opticflow_calc_thread; ///< The optical flow calcula static bool_t opticflow_got_result; ///< When we have an optical flow calculation static pthread_mutex_t opticflow_mutex; ///< Mutex lock fo thread safety +struct UdpSocket video_sock; + /* Static functions */ static void *opticflow_module_calc(void *data); ///< The main optical flow calculation thread static void opticflow_agl_cb(uint8_t sender_id, float distance); ///< Callback function of the ground altitude @@ -140,6 +144,12 @@ void opticflow_module_init(void) #if PERIODIC_TELEMETRY register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_OPTIC_FLOW_EST, opticflow_telem_send); #endif + +#if OPTICFLOW_DEBUG + + udp_socket_create(&video_sock, STRINGIFY(VIEWVIDEO_HOST), VIEWVIDEO_PORT_OUT, -1, VIEWVIDEO_BROADCAST); + +#endif } /** @@ -224,9 +234,14 @@ static void *opticflow_module_calc(void *data __attribute__((unused))) #if OPTICFLOW_DEBUG // Create a new JPEG image struct image_t img_jpeg; + image_create(&img_jpeg, opticflow_dev->w, opticflow_dev->h, IMAGE_JPEG); #endif + struct image_t img_gray; + image_create(&img_gray, opticflow_dev->w, opticflow_dev->h, IMAGE_YUV422); + + /* Main loop of the optical flow calculation */ while (TRUE) { // Try to fetch an image @@ -243,6 +258,9 @@ static void *opticflow_module_calc(void *data __attribute__((unused))) struct opticflow_result_t temp_result; opticflow_calc_frame(&opticflow, &temp_state, &img, &temp_result); + test_function(&img,&img_gray); + //image_to_grayscale(&img, &img_gray); + // Copy the result if finished pthread_mutex_lock(&opticflow_mutex); memcpy(&opticflow_result, &temp_result, sizeof(struct opticflow_result_t)); @@ -250,9 +268,9 @@ static void *opticflow_module_calc(void *data __attribute__((unused))) pthread_mutex_unlock(&opticflow_mutex); #if OPTICFLOW_DEBUG - jpeg_encode_image(&img, &img_jpeg, 70, FALSE); + jpeg_encode_image(&img_gray, &img_jpeg, 70, FALSE); rtp_frame_send( - &VIEWVIDEO_DEV, // UDP device + &video_sock, // UDP device &img_jpeg, 0, // Format 422 70, // Jpeg-Quality @@ -267,6 +285,7 @@ static void *opticflow_module_calc(void *data __attribute__((unused))) #if OPTICFLOW_DEBUG image_free(&img_jpeg); + image_free(&img_gray); #endif }