Skip to content

Commit

Permalink
Temperature thresholding working
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzhar committed Sep 21, 2017
1 parent 0ac67c7 commit 53359e6
Show file tree
Hide file tree
Showing 8 changed files with 345 additions and 65 deletions.
7 changes: 5 additions & 2 deletions bbb_life_tracker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ target_link_libraries (test_tracker LINK_PUBLIC
${LIB_GSTREAMER}
opencv_core
opencv_highgui
opencv_imgproc)
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)
opencv_imgproc
ncurses
)


183 changes: 140 additions & 43 deletions bbb_life_tracker/bbb_life_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <string>
#include <chrono>
#include <thread>
#include <stdio.h>
#include <ncurses.h>


#include "Lepton3.hpp"

Expand All @@ -20,29 +23,11 @@

using namespace std;

static bool close = false;
static bool quit = false;

void close_handler(int s)
{
if(s==2)
{
cout << endl << "Ctrl+C pressed..." << endl;
close = true;
}
}
void close_handler(int s);

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 << "\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;
}
void print_info();

int main( int argc, char *argv[] )
{
Expand All @@ -59,7 +44,14 @@ int main( int argc, char *argv[] )

sigaction(SIGINT, &sigIntHandler, NULL);
// <<<<< Enable Ctrl+C


// >>>>> Get char without enter
initscr();
timeout(0);
cbreak(); /* as per recommend Thomas Dickey */
noecho(); /* as per recommend Thomas Dickey */
// <<<<< Get char without enter

Lepton3::DebugLvl deb_lvl = Lepton3::DBG_NONE;

std::string track_mode;
Expand All @@ -68,7 +60,7 @@ int main( int argc, char *argv[] )
uint32_t res_ip_port;
std::string iface;

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

Expand All @@ -94,7 +86,7 @@ int main( int argc, char *argv[] )
return EXIT_FAILURE;
}

string res_port = argv[3];
string res_port = argv[4];

try
{
Expand All @@ -109,12 +101,11 @@ int main( int argc, char *argv[] )
return EXIT_FAILURE;
}

iface = argv[5];

iface = argv[4];

if( argc==6 )
if( argc==7 )
{
int dbg = atoi(argv[5]);
int dbg = atoi(argv[6]);

switch( dbg )
{
Expand Down Expand Up @@ -176,20 +167,16 @@ int main( int argc, char *argv[] )

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

if( lepton3.enableRadiometry( true ) < 0)
{
cerr << "Failed to enable radiometry!" << endl;
return EXIT_FAILURE;
}

if( lepton3.enableAgc( FALSE ) < 0)
if( lepton3.enableAgc( false ) < 0)
{
cerr << "Failed to disable AGC" << endl;
return EXIT_FAILURE;
}

if( lepton3.enableRgbOutput( false ) < 0 )
{
cerr << "Failed to disable RGB output" << endl;
return EXIT_FAILURE;
}

// >>>>> Life detection thresholds
Expand All @@ -201,26 +188,38 @@ int main( int argc, char *argv[] )
cout << " * Gain mode: " << str << endl;
}

if( gainMode==LEP_SYS_GAIN_MODE_AUTO ) // we want a fixed gain mode!
/*if( gainMode==LEP_SYS_GAIN_MODE_AUTO ) // we want a fixed gain mode!
{
if( lepton3.setGainMode( LEP_SYS_GAIN_MODE_HIGH ) < 0 )
{
cerr << "Failed to set Gain mode" << endl;
}
}*/

if( lepton3.setGainMode( LEP_SYS_GAIN_MODE_HIGH ) < 0 )
{
cerr << "Failed to set Gain mode" << endl;
return EXIT_FAILURE;
}

uint16_t min_thresh;
uint16_t max_thresh;

if( gainMode == LEP_SYS_GAIN_MODE_HIGH )
{
min_thresh = 300; // TODO evaluate these thresholds
max_thresh = 600; // TODO evaluate these thresholds
min_thresh = 3400; // TODO evaluate these thresholds
max_thresh = 4000; // TODO evaluate these thresholds
}
else
{
min_thresh = 300; // TODO evaluate these thresholds
max_thresh = 600; // TODO evaluate these thresholds
min_thresh = 3400; // TODO evaluate these thresholds
max_thresh = 4000; // TODO evaluate these thresholds
}

if( lepton3.enableRadiometry( true ) < 0)
{
cerr << "Failed to enable radiometry!" << endl;
return EXIT_FAILURE;
}
// <<<<< Life detection thresholds

Expand Down Expand Up @@ -256,7 +255,7 @@ int main( int argc, char *argv[] )

stpWtc.tic();

while(!close)
while(!quit)
{
uint16_t min;
uint16_t max;
Expand Down Expand Up @@ -294,6 +293,7 @@ int main( int argc, char *argv[] )
cv::Mat frameRGB;

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

cv::Mat frameYUV( h+h/2, w, CV_8UC1 );
cv::cvtColor( frameRGB, frameYUV, cv::COLOR_RGB2YUV_I420 );
Expand Down Expand Up @@ -324,7 +324,79 @@ int main( int argc, char *argv[] )
cout << "> Frame period: " << period_usec << " usec - FPS: " << freq << endl;
}
}


// >>>>> Keyboard interaction

int c = getch();

switch(c)
{
case 'P':
case 'p':
tracker.nextPalette();
break;

case 'A':
case 'a':
printw("\r");
min_thresh += 10;
tracker.setNewThresh(min_thresh, max_thresh);
break;

case 'Z':
case 'z':
printw("\r");
min_thresh -= 10;
tracker.setNewThresh(min_thresh, max_thresh);
break;

case 'S':
case 's':
printw("\r");
min_thresh += 1;
tracker.setNewThresh(min_thresh, max_thresh);
break;

case 'X':
case 'x':
printw("\r");
min_thresh -= 1;
tracker.setNewThresh(min_thresh, max_thresh);
break;

case 'D':
case 'd':
printw("\r");
max_thresh += 10;
tracker.setNewThresh(min_thresh, max_thresh);
break;

case 'C':
case 'c':
printw("\r");
max_thresh -= 10;
tracker.setNewThresh(min_thresh, max_thresh);
break;

case 'F':
case 'f':
printw("\r");
max_thresh += 1;
tracker.setNewThresh(min_thresh, max_thresh);
break;

case 'V':
case 'v':
printw("\r");
max_thresh -= 1;
tracker.setNewThresh(min_thresh, max_thresh);
break;
}


// <<<<< Keyboard interaction

//refresh();
std::this_thread::sleep_for(std::chrono::milliseconds(110));
}

Expand All @@ -339,7 +411,32 @@ int main( int argc, char *argv[] )
{
delete gstEncoderRes;
}


// ncurses close
endwin();


return EXIT_SUCCESS;
}

void close_handler(int s)
{
if(s==2)
{
cout << endl << "Ctrl+C pressed..." << endl;
quit = true;
}
}

void print_info()
{
cout << "Usage: " << endl << " bbb_life_tracker <trk_mode> <debug_ip_address> <raw_port> <res_port> <multicast_interface> [debug_level]" << endl << endl;
cout << " trk_mode:" << endl;
cout << " --avoid [-A] / --follow [-F] -> avoid/follow elements with a temperature compatible to life" << endl;
cout << " stream_ip_address -> the IP address of the destination of the video stream" << endl;
cout << " raw_port -> the port of the destination of the raw video stream" << endl;
cout << " res_port -> the port of the destination of the video stream with tracking result" << endl;
cout << " multicast_interface -> the network interface to multicast the video stream [use '' for unicast]" << endl;
cout << " debug_level [optional]:" << endl;
cout << " 0 [default] (no debug) - 1 (info debug) - 2 (full debug)" << endl << endl;
}
27 changes: 27 additions & 0 deletions bbb_life_tracker/flir_tracker/include/Palettes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef PALETTES_H
#define PALETTES_H

#include <stdint.h>

extern const uint8_t colormap_rainbow[];
extern const uint8_t colormap_grayscale[];
extern const uint8_t colormap_ironblack[];
extern const uint8_t colormap_blackHot[];
extern const uint8_t colormap_arctic[];
extern const uint8_t colormap_blueRed[];
extern const uint8_t colormap_coldest[];
extern const uint8_t colormap_contrast[];
extern const uint8_t colormap_doubleRainbow[];
extern const uint8_t colormap_grayRed[];
extern const uint8_t colormap_glowBow[];
extern const uint8_t colormap_hottest[];
extern const uint8_t colormap_lava[];
extern const uint8_t colormap_medical[];
extern const uint8_t colormap_wheel2[];
extern const uint8_t colormap_whiteHot[];

#define PALETTES_COUNT 16
extern const uint8_t* palettes[PALETTES_COUNT];


#endif
55 changes: 55 additions & 0 deletions bbb_life_tracker/flir_tracker/include/flir_tracker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef FLIR_TRACKER_H
#define FLIR_TRACKER_H

#include <opencv2/core/core.hpp>
#include "Palettes.h"

class FlirTracker
{
public:
typedef enum _track_res
{
TRK_RES_ERROR = 0,
TRK_RES_NONE = 1,
TRK_RES_FOUND = 2
} TrackRes;

typedef enum _track_mode
{
TRK_AVOID=0,
TRK_FOLLOW=1
} TrackMode;

FlirTracker(TrackMode trkMode, uint16_t minThresh, uint16_t maxThresh);
~FlirTracker();

void setNewThresh(uint16_t minThresh, uint16_t maxThresh);

TrackRes setNewFrame( cv::Mat frame16, uint16_t min, uint16_t max );
cv::Mat getResFrameRGB();

static cv::Mat normalizeFrame( const cv::Mat& frame16, uint16_t min, uint16_t max );

void nextPalette();

protected:
TrackRes doTrackStep();

private:
TrackMode mTrkMode;

uint16_t mMinThresh;
uint16_t mMaxThresh;

uint16_t mFrameMin;
uint16_t mFrameMax;

cv::Mat mFrame16;
cv::Mat mRes16;
cv::Mat mResRGB;
cv::Mat mResMask;

uint8_t mPaletteIdx;
};

#endif
Loading

0 comments on commit 53359e6

Please sign in to comment.