From 039c2b61019230bd761a8ae6ffb9a99b9a080af1 Mon Sep 17 00:00:00 2001 From: Ross Newman Date: Wed, 1 Mar 2017 11:28:57 +0000 Subject: [PATCH] Adding GigEVision camera support (requires Aravis) --- CMakeLists.txt | 10 +- camera/camera.h | 2 + camera/gstCamera.cpp | 5 +- camera/gstUtility.cpp | 2 +- camera/gvStream.cpp | 458 ++++++++++++++++++++++++++++ camera/gvStream.h | 89 ++++++ camera/rtpStream.cpp | 5 +- camera/rtpStream.h | 5 +- config.h | 12 +- display/debug.cpp | 34 +++ display/debug.h | 5 + imagenet-camera/imagenet-camera.cpp | 42 +-- 12 files changed, 626 insertions(+), 43 deletions(-) create mode 100644 camera/gvStream.cpp create mode 100644 camera/gvStream.h create mode 100644 display/debug.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 584fda34e..1653a15a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,7 @@ message("-- Detected ${CMAKE_SYSTEM_PROCESSOR} assumint TK1") set( CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; - -O3 -gencode arch=compute_32,code=sm_32, -std=c++11 -Xcompiler -D__CORRECT_ISO_CPP11_MATH_H_PROTO + -O3 -gencode arch=compute_32,code=sm_32, -std=c++11 -Xcompiler -D__CORRECT_ISO_CPP11_MATH_H_PROTO ) else() message("-- Detected ${CMAKE_SYSTEM_PROCESSOR} assumint TX1") @@ -45,6 +45,8 @@ set( ) endif() +# Aravis setup +include_directories(/usr/local/include/aravis-0.6) # setup project output paths set(PROJECT_OUTPUT_DIR ${PROJECT_BINARY_DIR}/${CMAKE_SYSTEM_PROCESSOR}) @@ -69,7 +71,7 @@ file(GLOB inferenceSources *.cpp *.cu camera/*.cpp cuda/*.cu display/*.cpp) file(GLOB inferenceIncludes *.h camera/*.h cuda/*.h display/*.h) cuda_add_library(jetson-inference SHARED ${inferenceSources}) -target_link_libraries(jetson-inference nvcaffe_parser nvinfer Qt4::QtGui GL GLEW gstreamer-1.0 gstapp-1.0) # gstreamer-0.10 gstbase-0.10 gstapp-0.10 +target_link_libraries(jetson-inference nvcaffe_parser nvinfer Qt4::QtGui GL GLEW gstreamer-1.0 gstapp-1.0 aravis-0.6) # gstreamer-0.10 gstbase-0.10 gstapp-0.10 # transfer all headers to the include directory @@ -90,10 +92,10 @@ endforeach() # build samples & tools -add_subdirectory(imagenet-console) +#add_subdirectory(imagenet-console) add_subdirectory(imagenet-camera) -add_subdirectory(detectnet-console) +#add_subdirectory(detectnet-console) add_subdirectory(detectnet-camera) #add_subdirectory(camera/gst-camera) diff --git a/camera/camera.h b/camera/camera.h index 0f84d0342..514328f1f 100644 --- a/camera/camera.h +++ b/camera/camera.h @@ -5,6 +5,8 @@ #ifndef __CAMERA_H__ #define __CAMERA_H__ #include +#include + class camera { public: diff --git a/camera/gstCamera.cpp b/camera/gstCamera.cpp index 2ece9502f..636d137ad 100644 --- a/camera/gstCamera.cpp +++ b/camera/gstCamera.cpp @@ -115,14 +115,17 @@ bool gstCamera::ConvertRGBtoRGBA( void* input, void** output ) { if( CUDA_FAILED(cudaMalloc(&mRGBA, mWidth * mHeight * sizeof(float4))) ) { - printf(LOG_CUDA "gstCamera -- failed to allocate memory for %ux%u RGBA texture\n", mWidth, mHeight); + printf(LOG_CUDA "gvCamera -- failed to allocate memory for %ux%u RGBA texture\n", mWidth, mHeight); return false; } } // USB webcam is RGB if( CUDA_FAILED(cudaRGBToRGBAf((uint8_t*)input, (float4*)mRGBA, mWidth, mHeight)) ) + { + printf(LOG_CUDA "gvCamera -- conversion cudaRGBToRGBAf failed\n"); return false; + } *output = mRGBA; return true; diff --git a/camera/gstUtility.cpp b/camera/gstUtility.cpp index 2977a3557..4bb0325ee 100644 --- a/camera/gstUtility.cpp +++ b/camera/gstUtility.cpp @@ -200,7 +200,7 @@ gboolean gst_message_print(GstBus* bus, GstMessage* message, gpointer user_data) #ifdef gst_tag_list_to_string gchar* txt = gst_tag_list_to_string(tags); #else - gchar* txt = "missing gst_tag_list_to_string()"; + gchar* txt = (gchar*)"missing gst_tag_list_to_string()"; #endif debug_print(LOG_GSTREAMER "gstreamer %s %s\n", GST_OBJECT_NAME(message->src), txt); diff --git a/camera/gvStream.cpp b/camera/gvStream.cpp new file mode 100644 index 000000000..844b9a137 --- /dev/null +++ b/camera/gvStream.cpp @@ -0,0 +1,458 @@ +/* + * + */ +#include "gvStream.h" +#if (VIDEO_SRC == VIDEO_GV_STREAM_SOURCE) +#include +#include +#include +#include "cudaMappedMemory.h" +#include "cudaYUV.h" +#include "cudaRGB.h" + +extern void DumpHex(const void* data, size_t size); + +/* + * error - wrapper for perror + */ +void error(char *msg) { + perror(msg); + exit(0); +} + +gvStream::gvStream(int height, int width) + : camera(height, width) +{ + cancel = FALSE; + mWidth = width; + mFrame = 0; + mGpuBuffer = 0; + arv_option_camera_name = NULL; + arv_option_debug_domains = NULL; + arv_option_snaphot = FALSE; + arv_option_trigger = NULL; + arv_option_software_trigger = -1; + arv_option_frequency = -1.0; + arv_option_width = -1; + arv_option_height = -1; + arv_option_horizontal_binning = -1; + arv_option_vertical_binning = -1; + arv_option_exposure_time_us = -1; + arv_option_gain = -1; + gboolean arv_option_auto_socket_buffer = FALSE; + gboolean arv_option_no_packet_resend = FALSE; + arv_option_packet_timeout = 20; + arv_option_frame_retention = 100; + arv_option_gv_stream_channel = -1; + arv_option_gv_packet_delay = -1; + arv_option_gv_packet_size = -1; + gboolean arv_option_realtime = FALSE; + gboolean arv_option_high_priority = FALSE; + gboolean arv_option_no_packet_socket = FALSE; + arv_option_chunks = NULL; + arv_option_bandwidth_limit = -1; +} + +bool +gvStream::ConvertRGBtoRGBA( void* input, void** output ) +{ + if( !input || !output ) + return false; + + if( !mRGBA ) + { + if( CUDA_FAILED(cudaMalloc(&mRGBA, mWidth * mHeight * sizeof(float4))) ) + { + printf(LOG_CUDA "gstCamera -- failed to allocate memory for %ux%u RGBA texture\n", mWidth, mHeight); + return false; + } + } + + // GigEVision camera is configured RGB8 + if( CUDA_FAILED(cudaRGBToRGBAf((uint8_t*)input, (float4*)mRGBA, mWidth, mHeight)) ) + return false; + + *output = mRGBA; + return true; +} + + +void +gvStream::set_cancel (int signal) +{ + cancel = TRUE; +} + +void +gvStream::new_buffer_cb (ArvStream *stream, ApplicationData *data) +{ + ArvBuffer *buffer; + size_t size = 0; + + buffer = arv_stream_try_pop_buffer (stream); + if (buffer != NULL) { + if (arv_buffer_get_status (buffer) == ARV_BUFFER_STATUS_SUCCESS) + data->buffer_count++; + + if (arv_buffer_get_payload_type (buffer) == ARV_BUFFER_PAYLOAD_TYPE_CHUNK_DATA && + data->chunks != NULL) { + int i; + + for (i = 0; data->chunks[i] != NULL; i++) + printf ("%s = %" G_GINT64_FORMAT "\n", data->chunks[i], + arv_chunk_parser_get_integer_value (data->chunk_parser, buffer, data->chunks[i])); + } + + /* Image processing here */ + mFrame++; + mBuffer = (void*)arv_buffer_get_data(buffer, &size); + printf("Frame %d, Buffer 0x%x, Size %d\n", mFrame, mBuffer, (int)size); + DumpHex(buffer, 128); + mFrameReady = true; + g_main_context_wakeup(context); + + arv_stream_push_buffer (stream, buffer); + } +} + +void +gvStream::stream_cb (void *user_data, ArvStreamCallbackType type, ArvBuffer *buffer) +{ + if (type == ARV_STREAM_CALLBACK_TYPE_INIT) { + if (arv_option_realtime) { + if (!arv_make_thread_realtime (10)) + printf ("Failed to make stream thread realtime\n"); + } else if (arv_option_high_priority) { + if (!arv_make_thread_high_priority (-10)) + printf ("Failed to make stream thread high priority\n"); + } + } +} + +gboolean +gvStream::periodic_task_cb (void *abstract_data) +{ + ApplicationData *data = (ApplicationData*)abstract_data; + + printf ("Frame rate = %d Hz\n", data->buffer_count); + data->buffer_count = 0; + + if (cancel) { + g_main_loop_quit (data->main_loop); + return FALSE; + } + + return TRUE; +} + +gboolean +gvStream::emit_software_trigger (void *abstract_data) +{ + ArvCamera *mCamera = (ArvCamera*)abstract_data; + + arv_camera_software_trigger (mCamera); + + return TRUE; +} + +void +gvStream::control_lost_cb (ArvGvDevice *gv_device) +{ + printf ("Control lost\n"); + + cancel = TRUE; +} + +gvStream::~gvStream(void) +{ + +} + +char* gvStream::str_format(ArvPixelFormat format) +{ + switch (format) + { + case 0x01080001 : + strcpy(tmp_str, "ARV_PIXEL_FORMAT_MONO_8"); + break; + case 0x01080009 : + strcpy(tmp_str, "ARV_PIXEL_FORMAT_BAYER_RG_8"); + break; + case 0x02180014 : + strcpy(tmp_str, "ARV_PIXEL_FORMAT_RGB_8_PACKED"); + break; + case 0x0210001f : + strcpy(tmp_str, "ARV_PIXEL_FORMAT_YUV_422_PACKED"); + break; + default: + sprintf(tmp_str, "Unknown 0x%x\n", format); + } + return tmp_str; +} + +bool gvStream::Open() +{ +#if 0 + GError *error = NULL; + int i; + + data.buffer_count = 0; + data.chunks = NULL; + data.chunk_parser = NULL; + + arv_g_thread_init (NULL); + arv_g_type_init (); + + context = g_main_context_new (); + + arv_debug_enable (arv_option_debug_domains); + + if (arv_option_camera_name == NULL) + debug_print ("Looking for the first available camera\n"); + else + debug_print ("Looking for camera '%s'\n", arv_option_camera_name); + + mCamera = arv_camera_new (arv_option_camera_name); + if (mCamera != NULL) { + gint payload; + gint x, y, width, height; + gint dx, dy; + double exposure; + guint64 n_completed_buffers; + guint64 n_failures; + guint64 n_underruns; + int gain; + software_trigger_source = 0; + ArvPixelFormat format; + gint maxHeight, maxWidth; + + if (arv_option_chunks != NULL) { + char *striped_chunks; + + striped_chunks = g_strdup (arv_option_chunks); + arv_str_strip (striped_chunks, " ,:;", ','); + data.chunks = g_strsplit_set (striped_chunks, ",", -1); + g_free (striped_chunks); + + data.chunk_parser = arv_camera_create_chunk_parser (mCamera); + + for (i = 0; data.chunks[i] != NULL; i++) { + char *chunk = g_strdup_printf ("Chunk%s", data.chunks[i]); + + g_free (data.chunks[i]); + data.chunks[i] = chunk; + } + } + + arv_camera_set_chunks (mCamera, arv_option_chunks); + arv_camera_set_region (mCamera, 0, 0, arv_option_width, arv_option_height); + arv_camera_set_binning (mCamera, arv_option_horizontal_binning, arv_option_vertical_binning); + arv_camera_set_exposure_time (mCamera, arv_option_exposure_time_us); + arv_camera_set_gain (mCamera, arv_option_gain); + + if (arv_camera_is_uv_device(mCamera)) { + arv_camera_uv_set_bandwidth (mCamera, arv_option_bandwidth_limit); + } + + if (arv_camera_is_gv_device (mCamera)) { + arv_camera_gv_select_stream_channel (mCamera, arv_option_gv_stream_channel); + arv_camera_gv_set_packet_delay (mCamera, arv_option_gv_packet_delay); + arv_camera_gv_set_packet_size (mCamera, arv_option_gv_packet_size); + arv_camera_gv_set_stream_options (mCamera, arv_option_no_packet_socket ? + ARV_GV_STREAM_OPTION_PACKET_SOCKET_DISABLED : + ARV_GV_STREAM_OPTION_NONE); + } + + arv_camera_get_height_bounds(mCamera, NULL, &maxHeight); + arv_camera_get_width_bounds(mCamera, NULL, &maxWidth); + arv_camera_get_region (mCamera, &x, &y, &width, &height); + if ((GetWidth() > width) && (GetHeight() > height)) + { + printf("ERROR requested resolution (%d x %d) is higher than the camera can support\n", GetWidth(), GetHeight()); + return false; + } + x = (maxWidth / 2) - (GetWidth() / 2); + y = (maxHeight / 2) - (GetHeight() / 2); + width = (maxWidth / 2) + (GetWidth() / 2); + height = (maxHeight / 2) + (GetHeight() / 2); + + arv_camera_set_region (mCamera, x, y, width, height); + + arv_camera_get_binning (mCamera, &dx, &dy); + exposure = arv_camera_get_exposure_time (mCamera); + payload = arv_camera_get_payload (mCamera); + gain = arv_camera_get_gain (mCamera); + + /* Set your camera defaults */ + arv_camera_set_pixel_format(mCamera, VIDEO_GV_PIXEL_FORMAT); + arv_camera_set_frame_rate(mCamera, VIDEO_GV_SRC_FRAMERATE); + + /* Check settings */ + format = arv_camera_get_pixel_format(mCamera); + +#if 1 + printf ("vendor name = %s\n", arv_camera_get_vendor_name (mCamera)); + printf ("model name = %s\n", arv_camera_get_model_name (mCamera)); + printf ("device id = %s\n", arv_camera_get_device_id (mCamera)); + printf ("pixel format = %s\n", str_format(format)); + if (arv_camera_is_frame_rate_available(mCamera)) + { + printf ("frame rate = %f\n", arv_camera_get_frame_rate(mCamera)); + } + printf ("region X = %d\n", x); + printf ("region Y = %d\n", y); + printf ("image width = %d\n", width); + printf ("image height = %d\n", height); + printf ("max width = %d\n", maxWidth); + printf ("max height = %d\n", maxHeight); + printf ("horizontal binning = %d\n", dx); + printf ("vertical binning = %d\n", dy); + printf ("payload = %d bytes\n", payload); + printf ("exposure = %g µs\n", exposure); + printf ("gain = %d dB\n", gain); + + if (arv_camera_is_gv_device (mCamera)) { + printf ("gv n_stream channels = %d\n", arv_camera_gv_get_n_stream_channels (mCamera)); + printf ("gv current channel = %d\n", arv_camera_gv_get_current_stream_channel (mCamera)); + printf ("gv packet delay = %" G_GINT64_FORMAT " ns\n", arv_camera_gv_get_packet_delay (mCamera)); + printf ("gv packet size = %d bytes\n", arv_camera_gv_get_packet_size (mCamera)); + } + + if (arv_camera_is_uv_device (mCamera)) { + guint min,max; + + arv_camera_uv_get_bandwidth_bounds (mCamera, &min, &max); + printf ("uv bandwidth limit = %d [%d..%d]\n", arv_camera_uv_get_bandwidth (mCamera), min, max); + } +#endif + + mStream = arv_camera_create_stream (mCamera, stream_cb, NULL); + if (mStream != NULL) { + if (ARV_IS_GV_STREAM (mStream)) { + if (arv_option_auto_socket_buffer) + g_object_set (mStream, + "socket-buffer", ARV_GV_STREAM_SOCKET_BUFFER_AUTO, + "socket-buffer-size", 0, + NULL); + if (arv_option_no_packet_resend) + g_object_set (mStream, + "packet-resend", ARV_GV_STREAM_PACKET_RESEND_NEVER, + NULL); + g_object_set (mStream, + "packet-timeout", (unsigned) arv_option_packet_timeout * 1000, + "frame-retention", (unsigned) arv_option_frame_retention * 1000, + NULL); + } + + for (i = 0; i < 50; i++) + arv_stream_push_buffer (mStream, arv_buffer_new (payload, NULL)); + + arv_camera_set_acquisition_mode (mCamera, ARV_ACQUISITION_MODE_CONTINUOUS); + + if (arv_option_frequency > 0.0) + arv_camera_set_frame_rate (mCamera, arv_option_frequency); + + if (arv_option_trigger != NULL) + arv_camera_set_trigger (mCamera, arv_option_trigger); + + if (arv_option_software_trigger > 0.0) { + arv_camera_set_trigger (mCamera, "Software"); + software_trigger_source = g_timeout_add ((double) (0.5 + 1000.0 / + arv_option_software_trigger), + emit_software_trigger, mCamera); + } + + arv_camera_start_acquisition (mCamera); + + g_signal_connect (mStream, "new-buffer", G_CALLBACK (new_buffer_cb), &data); + arv_stream_set_emit_signals (mStream, TRUE); + + g_signal_connect (arv_camera_get_device (mCamera), "control-lost", + G_CALLBACK (control_lost_cb), NULL); + + g_timeout_add_seconds (1, periodic_task_cb, &data); + + data.main_loop = g_main_loop_new (NULL, FALSE); + + old_sigint_handler = signal (SIGINT, set_cancel); + +// g_main_loop_run (data.main_loop); + + + } else + printf ("Can't create stream thread (check if the device is not already used)\n"); + + } else + { + printf ("No camera found\n"); + return false; + } + +#endif + return true; +} + +void gvStream::Close() +{ +#if 0 + arv_stream_get_statistics (mStream, &n_completed_buffers, &n_failures, &n_underruns); + + printf ("Completed buffers = %Lu\n", (unsigned long long) n_completed_buffers); + printf ("Failures = %Lu\n", (unsigned long long) n_failures); + printf ("Underruns = %Lu\n", (unsigned long long) n_underruns); +#endif + g_object_unref (mCamera); + + if (software_trigger_source > 0) + g_source_remove (software_trigger_source); + + signal (SIGINT, old_sigint_handler); + + g_main_loop_unref (data.main_loop); + + arv_camera_stop_acquisition (mCamera); + + g_object_unref (mStream); + + if (data.chunks != NULL) + g_strfreev (data.chunks); + + g_clear_object (&data.chunk_parser); +} + +bool gvStream::Capture( void** cpu, void** cuda, unsigned long timeout ) +{ + printf ("DEBUG1: set buffer 0x%x\n", mGpuBuffer); + // Allocate a buffer the first time we call this function + if (!mGpuBuffer) cudaMalloc(&mGpuBuffer, GetHeight() * GetWidth() * 3); + printf ("DEBUG: set buffer 0x%x\n", mGpuBuffer); + +#if 0 + mFrameReady = false; + if (!cancel) + { + printf("0 (%d x %d = %d)\n", GetWidth(), GetHeight(), GetWidth() * GetHeight() * 3); + while (!mFrameReady) + { + printf("1\n"); + g_main_context_iteration(context, TRUE); + } + mFrameReady = false; + printf("2\n"); + } +#endif + +// cudaMemcpy( mGpuBuffer, mBuffer, GetWidth() * GetHeight() * 3, cudaMemcpyHostToDevice ); + if (cudaMemset( mGpuBuffer, 0xaa, GetWidth() * GetHeight() * 3) != cudaSuccess) + printf ("ERROR: could not set buffer 0x%x\n", mGpuBuffer);; + +//bufferIn = (char*)malloc(height * width * 2); // Holds YUV data + + *cpu = (void*)mBuffer; + *cuda = (void*)gpuBuffer; + return true; +} + +#endif + + diff --git a/camera/gvStream.h b/camera/gvStream.h new file mode 100644 index 000000000..9138518f3 --- /dev/null +++ b/camera/gvStream.h @@ -0,0 +1,89 @@ +/* Example GigEVison packet from wireshark + + +*/ +#include "config.h" +#if (VIDEO_SRC == VIDEO_GV_STREAM_SOURCE) +#ifndef __GV_STREAM_H__ +#define __GV_STREAM_H__ + +#include +#include +#include +#include +#include "camera.h" + +typedef struct { + GMainLoop *main_loop; + int buffer_count; + ArvChunkParser *chunk_parser; + char **chunks; +} ApplicationData; + +static gboolean cancel; +static char *arv_option_camera_name; +static char *arv_option_debug_domains; +static gboolean arv_option_snaphot; +static char *arv_option_trigger; +static double arv_option_software_trigger; +static double arv_option_frequency; +static int arv_option_width; +static int arv_option_height; +static int arv_option_horizontal_binning; +static int arv_option_vertical_binning; +static double arv_option_exposure_time_us; +static int arv_option_gain; +static gboolean arv_option_auto_socket_buffer; +static gboolean arv_option_no_packet_resend; +static unsigned int arv_option_packet_timeout; +static unsigned int arv_option_frame_retention; +static int arv_option_gv_stream_channel; +static int arv_option_gv_packet_delay; +static int arv_option_gv_packet_size; +static gboolean arv_option_realtime; +static gboolean arv_option_high_priority; +static gboolean arv_option_no_packet_socket; +static char *arv_option_chunks; +static unsigned int arv_option_bandwidth_limit; + +static unsigned int mFrame; +static bool mFrameReady; +static GMainContext *context; +static const void *mBuffer; + +/** + * gvStream ethernet video data (Aravis) + */ +class gvStream : public camera +{ +public: + gvStream(int height, int width); + ~gvStream(); + int Transmit(char* rgbframe, bool gpuAddr) {return -1;}; /* Not supported */ + bool Open(); + void Close(); + bool Capture( void** cpu, void** cuda, unsigned long timeout=ULONG_MAX ); + bool ConvertRGBtoRGBA( void* input, void** output ); + /* GigE Vision functions */ + static void new_buffer_cb (ArvStream *stream, ApplicationData *data); + static void stream_cb (void *user_data, ArvStreamCallbackType type, ArvBuffer *buffer); + static gboolean periodic_task_cb (void *abstract_data); + static gboolean emit_software_trigger (void *abstract_data); + static void control_lost_cb (ArvGvDevice *gv_device); + static void set_cancel (int signal); + char* gpuBuffer; +private: + char *str_format(ArvPixelFormat format); + ApplicationData data; + ArvCamera *mCamera; + ArvStream *mStream; + guint software_trigger_source; + void (*old_sigint_handler)(int); + char *mGpuBuffer; + char tmp_str[200]; + + void* mRGBA; +}; + +#endif +#endif diff --git a/camera/rtpStream.cpp b/camera/rtpStream.cpp index 9cae68013..b570e159f 100644 --- a/camera/rtpStream.cpp +++ b/camera/rtpStream.cpp @@ -2,6 +2,8 @@ * Might need to add a route here: * sudo route add -net 239.0.0.0 netmask 255.0.0.0 eth1 */ +#include "rtpStream.h" +#if (VIDEO_SRC == VIDEO_RTP_STREAM_SOURCE) #include #include @@ -9,8 +11,6 @@ #include #include #include -#include "config.h" -#include "rtpStream.h" extern void DumpHex(const void* data, size_t size); @@ -487,4 +487,5 @@ int rtpStream::Transmit(char* rgbframe, bool gpuAddr) #endif return 0; } +#endif diff --git a/camera/rtpStream.h b/camera/rtpStream.h index 7b1ca6eea..f5bd2d206 100644 --- a/camera/rtpStream.h +++ b/camera/rtpStream.h @@ -24,7 +24,8 @@ gst-launch-1.0 udpsrc port=5004 caps="application/x-rtp, media=(string)video, cl Use his program to stream data to the udpsc example above on the tegra X1 */ - +#include "config.h" +#if (VIDEO_SRC == VIDEO_RTP_STREAM_SOURCE) #ifndef __RTP_STREAM_H__ #define __RTP_STREAM_H__ @@ -146,3 +147,5 @@ typedef struct #endif #endif + +#endif diff --git a/config.h b/config.h index 4bb642e63..547ac074c 100644 --- a/config.h +++ b/config.h @@ -2,8 +2,10 @@ #define VIDEO_GST_RTP_SRC 1 // Gstreamer udpsrc #define VIDEO_GST_V4L_SRC 2 // Gstreamer v4l2src #define VIDEO_RTP_STREAM_SOURCE 3 // Raw RTP +#define VIDEO_GV_STREAM_SOURCE 4 // GigE Vision (Aravis) #define VIDEO_SRC VIDEO_GST_V4L_SRC +//#define VIDEO_SRC VIDEO_GV_STREAM_SOURCE #define SDL_DISPLAY 1 #define GST_RTP_SINK 0 #define ABACO 1 @@ -17,14 +19,20 @@ #define WIDTH 1920 #endif +// +// GigEVision camera settings +// +#define VIDEO_GV_PIXEL_FORMAT ARV_PIXEL_FORMAT_RGB_8_PACKED +#define VIDEO_GV_SRC_FRAMERATE 25.0 + // // Gstreamer V4L2 settings // -#define VIDEO_GST_V4L_SRC_DEVICE "/dev/video0" +#define VIDEO_GST_V4L_SRC_DEVICE "/dev/video1" // Note '/dev/video0' is the CSI camera on the TX dev platform #define VIDEO_GST_V4L_SRC_FRAMERATE 30 // -// Connection details +// RTP Connection details // #define IP_UNICAST "127.0.0.1" #define IP_MULTICAST_OUT "239.192.1.198" diff --git a/display/debug.cpp b/display/debug.cpp new file mode 100644 index 000000000..9ffa3e871 --- /dev/null +++ b/display/debug.cpp @@ -0,0 +1,34 @@ +#include +#include + +#if 1 +void DumpHex(const void* data, size_t size) { + char ascii[17]; + size_t i, j; + ascii[16] = '\0'; + for (i = 0; i < size; ++i) { + printf("%02X ", ((unsigned char*)data)[i]); + if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') { + ascii[i % 16] = ((unsigned char*)data)[i]; + } else { + ascii[i % 16] = '.'; + } + if ((i+1) % 8 == 0 || i+1 == size) { + printf(" "); + if ((i+1) % 16 == 0) { + printf("| %s \n", ascii); + } else if (i+1 == size) { + ascii[(i+1) % 16] = '\0'; + if ((i+1) % 16 <= 8) { + printf(" "); + } + for (j = (i+1) % 16; j < 16; ++j) { + printf(" "); + } + printf("| %s \n", ascii); + } + } + } +} +#endif + diff --git a/display/debug.h b/display/debug.h index c5acda2b1..d7ec308bd 100644 --- a/display/debug.h +++ b/display/debug.h @@ -1,5 +1,9 @@ #ifndef __DEBUG_H__ #define __DEBUG_H__ + +#include +#include + #define DEBUG 0 #if !DEBUG @@ -11,4 +15,5 @@ fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, ##args) #endif #endif + #endif diff --git a/imagenet-camera/imagenet-camera.cpp b/imagenet-camera/imagenet-camera.cpp index 16f0bd44a..09eee41bb 100644 --- a/imagenet-camera/imagenet-camera.cpp +++ b/imagenet-camera/imagenet-camera.cpp @@ -10,6 +10,7 @@ #else #include "rtpStream.h" #include "gstCamera.h" +#include "gvStream.h" #endif #include "config.h" @@ -37,35 +38,6 @@ using namespace std; -void DumpHex(const void* data, size_t size) { - char ascii[17]; - size_t i, j; - ascii[16] = '\0'; - for (i = 0; i < size; ++i) { - printf("%02X ", ((unsigned char*)data)[i]); - if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') { - ascii[i % 16] = ((unsigned char*)data)[i]; - } else { - ascii[i % 16] = '.'; - } - if ((i+1) % 8 == 0 || i+1 == size) { - printf(" "); - if ((i+1) % 16 == 0) { - printf("| %s \n", ascii); - } else if (i+1 == size) { - ascii[(i+1) % 16] = '\0'; - if ((i+1) % 16 <= 8) { - printf(" "); - } - for (j = (i+1) % 16; j < 16; ++j) { - printf(" "); - } - printf("| %s \n", ascii); - } - } - } -} - bool signal_recieved = false; void sig_handler(int signo) @@ -190,6 +162,10 @@ int main( int argc, char** argv ) camera->rtpStreamIn((char*)IP_UNICAST, IP_PORT_IN); #endif +#if VIDEO_SRC==VIDEO_GV_STREAM_SOURCE + gvStream* camera = new gvStream(HEIGHT, WIDTH); +#endif + #if VIDEO_SRC==VIDEO_NV // USB Nvida TX1 CSI Webcam gstCamera* camera = gstCamera::Create(); #endif @@ -278,9 +254,10 @@ int main( int argc, char** argv ) // get the latest frame +printf("Captureding\n"); if( !camera->Capture(&imgCPU, &imgCUDA, 1000) ) printf("\nimagenet-camera: failed to capture frame\n"); - +printf("Captured\n"); #if VIDEO_SRC==VIDEO_GST_RTP_SRC if ( !camera->ConvertYUVtoRGBA(imgCUDA, &imgRGBA) ) printf("imagenet-camera: failed to convert from YUV to RGBAf\n"); @@ -289,15 +266,16 @@ int main( int argc, char** argv ) if ( !ConvertYUVtoRGBf((uint8_t*)imgCUDA, &imgRGBA, camera->GetWidth(), camera->GetHeight() ) ) printf("imagenet-camera: failed to convert from YUV to RGBAf\n"); #endif -#if VIDEO_SRC==VIDEO_GST_V4L_SRC +#if VIDEO_SRC==VIDEO_GST_V4L_SRC || VIDEO_GV_STREAM_SOURCE if ( !camera->ConvertRGBtoRGBA(imgCUDA, &imgRGBA) ) printf("imagenet-camera: failed to convert from RGB to RGBAf\n"); +printf("Converted\n"); #endif #if VIDEO_SRC==VIDEO_NV if ( !camera->ConvertNV12toRGBA(imgCUDA, &imgRGBA) ) printf("imagenet-camera: failed to convert from NV12 to RGBAf\n"); #endif - +printf("Classifying %dx%d\n", camera->GetWidth(), camera->GetHeight()); // classify image const int img_class = net->Classify((float*)imgRGBA, camera->GetWidth(), camera->GetHeight(), &confidence);