Skip to content

Commit

Permalink
Add test_tracker to verify bbb_life_tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzhar committed Sep 21, 2017
1 parent 0bfa5a3 commit 0ac67c7
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 88 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ set(CMAKE_DEBUG_POSTFIX "_d")
set (CMAKE_CXX_STANDARD 11)
#########################################################

# Library source code
add_subdirectory (grabber_lib)

# bbb_life_tracker
add_subdirectory (bbb_life_tracker)

# Library source code
add_subdirectory (grabber_lib)

# OpenCV demo
add_subdirectory (opencv_demo)

Expand Down
26 changes: 17 additions & 9 deletions bbb_life_tracker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ set(LIB_GSTREAMER ${GSTREAMER_LIBRARIES} ${GSTREAMER_APP_LIBRARIES}

#########################################################
# SOURCES
file(GLOB_RECURSE DEMO_SRC *.c *.cpp)
# HEADERS
file(GLOB_RECURSE DEMO_HDR *.h *.hpp)
set(TRK_SRC ${CMAKE_CURRENT_SOURCE_DIR}/flir_tracker/src/flir_tracker.cpp
${CMAKE_CURRENT_SOURCE_DIR}/flir_tracker/src/Palettes.cpp )
set(ENC_SRC ${CMAKE_CURRENT_SOURCE_DIR}/videoEncoder/src/videoEncoder.cpp )
#########################################################

include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/videoEncoder/include
Expand All @@ -27,11 +27,19 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/videoEncoder/include
${CMAKE_CURRENT_SOURCE_DIR}/flir_tracker/include
)


add_executable (bbb_life_tracker ${DEMO_SRC} )
target_link_libraries (bbb_life_tracker LINK_PUBLIC
lepton3_grabber
add_executable (test_tracker test_tracker.cpp ${TRK_SRC})
target_link_libraries (test_tracker LINK_PUBLIC
${LIB_GSTREAMER}
opencv_core
opencv_highgui
opencv_core
opencv_highgui
opencv_imgproc)

add_executable (bbb_life_tracker bbb_life_tracker.cpp ${ENC_SRC} ${TRK_SRC} )
target_link_libraries (bbb_life_tracker LINK_PUBLIC
lepton3_grabber
${LIB_GSTREAMER}
opencv_core
opencv_highgui
opencv_imgproc)


124 changes: 89 additions & 35 deletions bbb_life_tracker/bbb_life_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ void print_info()
cout << "Usage: " << endl << "\t bbb_life_tracker <trk_mode> <debug_ip_address> <debug_port> <multicast_interface> [debug_level]" << endl << endl;
cout << "\ttrk_mode:" << endl;
cout << "\t\t --avoid [-A] / --follow [-F] -> avoid/follow elements with a temperature compatible to life" << endl;
cout << "\tdebug_ip_address -> the IP address of the destination of the video stream" << endl;
cout << "\tdebug_port -> the port of the destination of the video stream" << endl;
cout << "\tstream_ip_address -> the IP address of the destination of the video stream" << endl;
cout << "\traw_port -> the port of the destination of the raw video stream" << endl;
cout << "\tres_port -> the port of the destination of the video stream with tracking result" << endl;
cout << "\tmulticast_interface -> the network interface to multicast the video stream [use \"\" for unicast]" << endl;
cout << "\tdebug_level [optional]:" << endl;
cout << "\t\t 0 [default] (no debug) - 1 (info debug) - 2 (full debug)" << endl << endl;
}

int main( int argc, char *argv[] )
int main( int argc, char *argv[] )
{
gst_init( &argc, &argv );

Expand All @@ -63,10 +64,11 @@ int main( int argc, char *argv[] )

std::string track_mode;
std::string ip_addr;
uint32_t ip_port;
uint32_t raw_ip_port;
uint32_t res_ip_port;
std::string iface;

if( argc != 5 || argc != 6 )
if( argc != 6 || argc != 7 )
{
print_info();

Expand All @@ -76,17 +78,33 @@ int main( int argc, char *argv[] )
{
track_mode = argv[1];
ip_addr = argv[2];
string port = argv[3];

string raw_port = argv[3];

try
{
raw_ip_port = std::stoul(raw_port);
}
catch( const std::invalid_argument& ia )
{
print_info();

cerr << endl << "Invalid argument for 'raw_port': " << ia.what() << endl;

return EXIT_FAILURE;
}

string res_port = argv[3];

try
{
ip_port = std::stoul(port);
res_ip_port = std::stoul(res_port);
}
catch( const std::invalid_argument& ia )
{
print_info();

cerr << endl << "Invalid argument for 'debug_port': " << ia.what() << endl;
cerr << endl << "Invalid argument for 'res_port': " << ia.what() << endl;

return EXIT_FAILURE;
}
Expand Down Expand Up @@ -116,18 +134,45 @@ int main( int argc, char *argv[] )
}
}

// >>>>> Create GStreamer encoder
videoEncoder* gstEncoder = NULL;
// >>>>> Create GStreamer encoder for raw stream
videoEncoder* gstEncoderRaw = NULL;

gstEncoderRaw = videoEncoder::Create( 160, 120,
iface,
ip_addr,
raw_ip_port,
1024,
"gst_encoder");

if( !gstEncoderRaw)
{
cerr << "Cannot create Encoder for Raw Video Stream" << endl;

return EXIT_FAILURE;
}

gstEncoderRaw->Open();
// <<<<< Create GStreamer encoder for raw stream

gstEncoder = videoEncoder::Create( 160, 120,
// >>>>> Create GStreamer encoder for res stream
videoEncoder* gstEncoderRes = NULL;

gstEncoderRes = videoEncoder::Create( 160, 120,
iface,
ip_addr,
ip_port,
res_ip_port,
1024,
"gst_encoder");

gstEncoder->Open();
// <<<<< Create GStreamer encoder
if( !gstEncoderRes)
{
cerr << "Cannot create Encoder for Result Video Stream" << endl;

return EXIT_FAILURE;
}

gstEncoderRes->Open();
// <<<<< Create GStreamer encoder for res stream */

Lepton3 lepton3( "/dev/spidev1.0", 1, deb_lvl );

Expand Down Expand Up @@ -193,8 +238,6 @@ int main( int argc, char *argv[] )
}
else
{
lepton3.stop();

print_info();

cerr << endl << "Invalid argument for 'trk_mode'" << endl;
Expand Down Expand Up @@ -229,42 +272,48 @@ int main( int argc, char *argv[] )
double freq = (1000.*1000.)/period_usec;

cv::Mat frame16( h, w, CV_16UC1 );
cv::Mat frameRGB( h, w, CV_8UC3 );

cv::Mat frameRes;

memcpy( frame16.data, data16, w*h*sizeof(uint16_t) );

// >>>>> Tracking
if( !tracker.setNewFrame( frame16 ) )
if( tracker.setNewFrame( frame16, min, max ) != FlirTracker::TRK_RES_ERROR )
{
if( deb_lvl>=Lepton3::DBG_INFO )
{
cout << "*** Error performing tracking step on frame #" << frameIdx << endl;
}

frameRes = tracker.getResFrameRGB();
}
// <<<<< Tracking

// >>>>> Rescaling/Normalization to 8bit to visualize data
double diff = static_cast<double>(max - min); // Image range
double scale = 255./diff; // Scale factor

frame16 -= min; // Bias
frame16 *= scale; // Rescale data

cv::Mat frame8;
frame16.convertTo( frame8, CV_8UC1 );
// <<<<< Rescaling/Normalization to 8bit to visualize data
if(gstEncoderRaw)
{
cv::Mat frameRGB;

cv::cvtColor( frame8,frameRGB, CV_GRAY2RGB );
frameRGB = FlirTracker::normalizeFrame( frame16, min, max );

if(gstEncoder)
{
cv::Mat frameYUV( h+h/2, w, CV_8UC1 );
cv::cvtColor( frameRGB, frameYUV, cv::COLOR_RGB2YUV_I420 );
gstEncoder->PushFrame( (uint8_t*)frameYUV.data );
gstEncoderRaw->PushFrame( (uint8_t*)frameYUV.data );

if( deb_lvl>=Lepton3::DBG_FULL )
{
cout << "Frame pushed" << endl;
cout << "Frame Raw pushed" << endl;
}
}

if(gstEncoderRes && !frameRes.empty() )
{
cv::Mat frameYUV( h+h/2, w, CV_8UC1 );
cv::cvtColor( frameRes, frameYUV, cv::COLOR_RGB2YUV_I420 );
gstEncoderRes->PushFrame( (uint8_t*)frameYUV.data );

if( deb_lvl>=Lepton3::DBG_FULL )
{
cout << "Frame Res pushed" << endl;
}
}

Expand All @@ -281,9 +330,14 @@ int main( int argc, char *argv[] )

lepton3.stop();

if(gstEncoder)
if(gstEncoderRaw)
{
delete gstEncoderRaw;
}

if(gstEncoderRes)
{
delete gstEncoder;
delete gstEncoderRes;
}


Expand Down
Loading

0 comments on commit 0ac67c7

Please sign in to comment.