You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
429 lines
17 KiB
429 lines
17 KiB
#include "rgooseNodeSensor.h"
|
|
#include <opencv2/opencv.hpp>
|
|
|
|
#define LOG( X ) m_pLog->Log( "NODSEN", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "NODSEN", this, _LOG_ERROR, X )
|
|
|
|
argusNodeSensor::argusNodeSensor( uint32_t id ):argusNetNode( id ),m_oPosition(){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pTargetFilter = NULL;
|
|
};
|
|
|
|
argusNodeSensor::argusNodeSensor( DBC_NODE_DATA *Data ):argusNetNode( Data ),m_oPosition(){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pTargetFilter = NULL;
|
|
};
|
|
|
|
|
|
argusNodeSensor::~argusNodeSensor(){
|
|
|
|
};
|
|
|
|
#define SKIP_LINE_PIXELS 28
|
|
#define HEIGHT 512
|
|
#define WIDTH 1024
|
|
// scale factor -> 4/9
|
|
|
|
bool argusNodeSensor::handleDeviceDraw( uint8_t kID, void *th_data, size_t th_size, bool byMinimum ){
|
|
LOG("TRY SAVE");
|
|
if( th_data == NULL ) return false;
|
|
if( th_size == 0 ) return false;
|
|
if( m_pDBC == NULL ) return false;
|
|
LOG("SAVE");
|
|
CSTR old = m_pDBC->getLRFDraw( getNodeID() );
|
|
if ( old ) {
|
|
// delete old draw
|
|
LOG("DELETE OLD DRAW");
|
|
char filename[256];
|
|
sprintf( filename, "data/device_draws/%s_100.png", old );
|
|
if( fileExist( filename ) ){
|
|
unlink( filename );
|
|
};
|
|
sprintf( filename, "data/device_draws/%s_map.png", old );
|
|
if( fileExist( filename ) ){
|
|
unlink( filename );
|
|
};
|
|
free(old);
|
|
} else {
|
|
LOG("NO OLD DRAW");
|
|
}
|
|
CSTR uid = getUniqID_MD5();
|
|
if( uid == NULL ) return false;
|
|
switch (getNodeType()) {
|
|
case ARGUS_ALS_SENSOR:
|
|
case ARGUS_LFS_SENSOR:
|
|
case ARGUS_PLS_200_SENSOR:
|
|
case ARGUS_PLS_360_SENSOR:
|
|
case ARGUS_NET_PLS_200:{
|
|
|
|
break;
|
|
};
|
|
case ARGUS_3D_SENSOR:{
|
|
char * emptyBG = "data/assets/images/empty_3d.png";
|
|
thresholdNode * ptr = (thresholdNode *) th_data;
|
|
LOG("SAVE 3D DRAW!");
|
|
if ( fileExist( emptyBG ) ) {
|
|
LOG("BG Exists");
|
|
cv::Mat tImage = cv::imread( emptyBG, cv::IMREAD_UNCHANGED );
|
|
if( tImage.rows != 512 || tImage.cols != 1024 ){
|
|
LOG_ERROR( "Background Image wrong size (should be 1024x512)!" );
|
|
free( uid );
|
|
return false;
|
|
} else LOG("BG READ");
|
|
|
|
uint8_t * tMemory = tImage.data;
|
|
thresholdNode * cNode = NULL;
|
|
uint8_t * cPixel = NULL;
|
|
int pix = 0;
|
|
int mem = 0;
|
|
bool s_bit = false;
|
|
bool no_data = false;
|
|
float tVal;
|
|
bool master = ( kID < 16 );
|
|
LOG("Start Draw ");
|
|
for( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
|
|
if( ( idx % 4 ) == 0 ){
|
|
mem++;
|
|
if ( master ) {
|
|
cNode = ptr + TH_SIZE_NODES - mem - 1;
|
|
} else {
|
|
cNode = ptr + mem - 1;
|
|
};
|
|
if( !s_bit ) s_bit = cNode->values.sbit;
|
|
if( !no_data ) no_data = ( cNode->values.cnt == 0 );
|
|
if( !s_bit && !no_data ){
|
|
if( byMinimum ) {
|
|
tVal = ((float)cNode->values.min) / 4096.f;
|
|
} else {
|
|
tVal = ((float)cNode->values.max) / 4096.f;
|
|
};
|
|
};
|
|
};
|
|
if( ( idx % 9 ) == 0 ){
|
|
if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) {
|
|
cPixel = tMemory + (pix << 2);
|
|
pix++;
|
|
if( s_bit ) { // Set Red
|
|
cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff;
|
|
} else {
|
|
if( no_data ) { // Set Blue
|
|
cPixel[0] = 0xff; cPixel[1] = 0x00; cPixel[2] = 0x00; cPixel[3] = 0xff;
|
|
} else {
|
|
uint32_t tColor;
|
|
tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
|
|
cPixel[0] = ( tColor >> 24 ) & 0xFF;
|
|
cPixel[1] = ( tColor >> 16 ) & 0xFF;
|
|
cPixel[2] = ( tColor >> 8 ) & 0xFF;
|
|
cPixel[3] = tColor & 0xFF;
|
|
};
|
|
};
|
|
s_bit = false;
|
|
no_data = false;
|
|
};
|
|
};
|
|
};
|
|
|
|
char filename[256];
|
|
sprintf( filename, "data/device_draws/%s_100.png", uid );
|
|
//int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace );
|
|
vector<int> compression_params;
|
|
compression_params.push_back( cv::IMWRITE_PNG_COMPRESSION );
|
|
compression_params.push_back(9);
|
|
if(! cv::imwrite( filename, tImage, compression_params ) ){
|
|
tImage.release();
|
|
free( uid );
|
|
return false;
|
|
};
|
|
tImage.release();
|
|
LOG("Draw Saved!");
|
|
|
|
cv::Mat tMap( Q_SCAN_COUNT, TH_LINE_NODES, CV_8UC4 );
|
|
LOG("Map Creating");
|
|
tMemory = tMap.data;
|
|
for( int j = 0; j < Q_SCAN_COUNT; j++ ){
|
|
for( int i = 0; i < TH_LINE_NODES; i++ ){
|
|
//cNode = ptr+(j*i);
|
|
//cNode = &ptr[ ( TH_LINE_NODES * j ) + i ];
|
|
int ids = 0;
|
|
int idd = 0;
|
|
if ( master ) {
|
|
//cNode = ptr+makeIds( i, j , true );
|
|
//cPixel = tMemory+( cSpace * makeIds( i, j , false ));
|
|
ids = makeIds( i, j , true );
|
|
idd = 4 * makeIds( i, j , false );
|
|
//cNode = ptr + ( i * j );
|
|
//cPixel = tMemory + ( cSpace * i * j );
|
|
} else {
|
|
//cNode = ptr+makeIds( i, j , false );
|
|
//cPixel = tMemory+( cSpace * makeIds( i, j , false ));
|
|
ids = makeIds( i, j , false );
|
|
idd = 4 * makeIds( i, j , false );
|
|
};
|
|
|
|
cNode = ptr + ids ;
|
|
cPixel = tMemory + idd;
|
|
|
|
if( 0 ) { // Monochrome
|
|
#ifdef CHECK_SUN_BIT
|
|
if( cNode->values.sbit ) {
|
|
cPixel[0] = 0;
|
|
} else {
|
|
cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
|
|
};
|
|
#else
|
|
cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
|
|
#endif
|
|
} else {
|
|
#ifdef CHECK_SUN_BIT
|
|
if( cNode->values.sbit ) {
|
|
// Set Red
|
|
cPixel[0] = 0x00;
|
|
cPixel[1] = 0x00;
|
|
cPixel[2] = 0xff;
|
|
cPixel[3] = 0xff;
|
|
} else {
|
|
if( cNode->values.cnt == 0 ) {
|
|
// Set Blue
|
|
cPixel[0] = 0xff;
|
|
cPixel[1] = 0x00;
|
|
cPixel[2] = 0x00;
|
|
cPixel[3] = 0xff;
|
|
} else {
|
|
uint32_t tColor;
|
|
float tVal = ((float) cNode->values.min ) / 4096.f;
|
|
tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
|
|
cPixel[0] = ( tColor >> 24 ) & 0xFF;
|
|
cPixel[1] = ( tColor >> 16 ) & 0xFF;
|
|
cPixel[2] = ( tColor >> 8 ) & 0xFF;
|
|
cPixel[3] = tColor & 0xFF;
|
|
};
|
|
};
|
|
#else
|
|
if( cNode->values.cnt == 0 ) {
|
|
// Set Blue
|
|
cPixel[0] = 0xff;
|
|
cPixel[1] = 0x00;
|
|
cPixel[2] = 0x00;
|
|
cPixel[3] = 0xff;
|
|
} else {
|
|
uint32_t tColor;
|
|
float tVal = ((float) cNode->values.min ) / 4096.f;
|
|
tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
|
|
cPixel[0] = ( tColor >> 24 ) & 0xFF;
|
|
cPixel[1] = ( tColor >> 16 ) & 0xFF;
|
|
cPixel[2] = ( tColor >> 8 ) & 0xFF;
|
|
cPixel[3] = tColor & 0xFF;
|
|
};
|
|
#endif
|
|
};
|
|
};
|
|
};
|
|
sprintf( filename, "data/device_draws/%s_map.png", uid );
|
|
LOG(filename);
|
|
if(! cv::imwrite( filename, tMap, compression_params ) ){
|
|
tMap.release();
|
|
free( uid );
|
|
return false;
|
|
};
|
|
tMap.release();
|
|
m_pDBC->addLRFDraw( getNodeID(), TH_SIZE_NODES, uid, kID, 1, true );
|
|
} else {
|
|
LOG_ERROR( "Background Image is Missed!" );
|
|
free( uid );
|
|
return false;
|
|
};
|
|
break;
|
|
};
|
|
};
|
|
free( uid );
|
|
return true;
|
|
};
|
|
|
|
/*
|
|
#define STB_IMAGE_IMPLEMENTATION
|
|
#include "../data/stbi/stb_image.h"
|
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
|
#include "../data/stbi/stb_image_write.h"
|
|
#undef STB_IMAGE_WRITE_IMPLEMENTATION
|
|
#undef STB_IMAGE_IMPLEMENTATION
|
|
|
|
|
|
|
|
bool argus3DLIDAR::saveTHPicture( thresholdNode *ptr, CSTR uid, bool master, bool byMinimum, bool monochrome ){
|
|
uint8_t *tMemory = NULL;
|
|
thresholdNode *cNode = NULL;
|
|
uint8_t *cPixel = NULL;
|
|
int cSpace;
|
|
|
|
|
|
int x, y;
|
|
tMemory = stbi_load( "data/assets/images/empty_3d.png", &x, &y, &cSpace, STBI_default );
|
|
|
|
if( tMemory == NULL ){
|
|
LOG_ERROR("Draw Memory Alloc Eror!");
|
|
return false;
|
|
};
|
|
|
|
if( x != 1024 || y != 512 ){
|
|
LOG("Wrong IMG Size!");
|
|
free( tMemory );
|
|
return NULL;
|
|
};
|
|
|
|
int pix = 0;
|
|
int mem = 0;
|
|
bool s_bit = false;
|
|
bool no_data = false;
|
|
float tVal;
|
|
|
|
for ( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
|
|
|
|
if( ( idx % 4 ) == 0 ){
|
|
mem++;
|
|
if ( master ) {
|
|
cNode = ptr + TH_SIZE_NODES - mem - 1;
|
|
} else {
|
|
cNode = ptr + mem - 1;
|
|
};
|
|
if( !s_bit ) s_bit = cNode->values.sbit;
|
|
if( !no_data ) no_data = ( cNode->values.cnt == 0 );
|
|
if( !s_bit && !no_data ){
|
|
if( byMinimum ) {
|
|
tVal = ((float)cNode->values.min) / 4096.f;
|
|
} else {
|
|
tVal = ((float)cNode->values.max) / 4096.f;
|
|
};
|
|
};
|
|
};
|
|
|
|
if( ( idx % 9 ) == 0 ){
|
|
if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) {
|
|
cPixel = tMemory + (pix << 2);
|
|
pix++;
|
|
if( s_bit ) { // Set Red
|
|
cPixel[0] = 0x00; cPixel[1] = 0xff; cPixel[2] = 0x00; cPixel[3] = 0xff;
|
|
} else {
|
|
if( no_data ) { // Set Blue
|
|
cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff;
|
|
} else {
|
|
uint32_t tColor;
|
|
tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
|
|
cPixel[0] = ( tColor >> 24 ) & 0xFF;
|
|
cPixel[1] = ( tColor >> 16 ) & 0xFF;
|
|
cPixel[2] = ( tColor >> 8 ) & 0xFF;
|
|
cPixel[3] = tColor & 0xFF;
|
|
};
|
|
};
|
|
s_bit = false;
|
|
no_data = false;
|
|
}
|
|
};
|
|
};
|
|
|
|
char filename[256];
|
|
sprintf( filename, "data/device_draws/%s_100.png", uid );
|
|
int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace );
|
|
free( tMemory );
|
|
if( RetVal == 0 ) return false;
|
|
|
|
if( monochrome ) {
|
|
cSpace = 1;
|
|
} else {
|
|
cSpace = 4;
|
|
};
|
|
|
|
tMemory = (uint8_t *) malloc( TH_SIZE_NODES * cSpace );
|
|
if( tMemory == NULL ){
|
|
LOG_ERROR("Map Memory Alloc Eror!");
|
|
return false;
|
|
};
|
|
|
|
for (int j = 0; j < Q_SCAN_COUNT; j++) {
|
|
for ( int i = 0; i < TH_LINE_NODES; i++ ) {
|
|
//cNode = ptr+(j*i);
|
|
//cNode = &ptr[ ( TH_LINE_NODES * j ) + i ];
|
|
int ids = 0;
|
|
int idd = 0;
|
|
if ( master ) {
|
|
//cNode = ptr+makeIds( i, j , true );
|
|
//cPixel = tMemory+( cSpace * makeIds( i, j , false ));
|
|
ids = makeIds( i, j , true );
|
|
idd = cSpace * makeIds( i, j , false );
|
|
//cNode = ptr + ( i * j );
|
|
//cPixel = tMemory + ( cSpace * i * j );
|
|
} else {
|
|
//cNode = ptr+makeIds( i, j , false );
|
|
//cPixel = tMemory+( cSpace * makeIds( i, j , false ));
|
|
ids = makeIds( i, j , false );
|
|
idd = cSpace * makeIds( i, j , false );
|
|
};
|
|
|
|
cNode = ptr + ids ;
|
|
cPixel = tMemory + idd;
|
|
|
|
if( monochrome ) {
|
|
#ifdef CHECK_SUN_BIT
|
|
if( cNode->values.sbit ) {
|
|
cPixel[0] = 0;
|
|
} else {
|
|
cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
|
|
};
|
|
#else
|
|
cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
|
|
#endif
|
|
} else {
|
|
#ifdef CHECK_SUN_BIT
|
|
if( cNode->values.sbit ) {
|
|
// Set Red
|
|
cPixel[0] = 0x00;
|
|
cPixel[1] = 0xff;
|
|
cPixel[2] = 0x00;
|
|
cPixel[3] = 0xff;
|
|
} else {
|
|
if( cNode->values.cnt == 0 ) {
|
|
// Set Blue
|
|
cPixel[0] = 0x00;
|
|
cPixel[1] = 0x00;
|
|
cPixel[2] = 0xff;
|
|
cPixel[3] = 0xff;
|
|
} else {
|
|
uint32_t tColor;
|
|
float tVal = ((float) cNode->values.min ) / 4096.f;
|
|
tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
|
|
cPixel[0] = ( tColor >> 24 ) & 0xFF;
|
|
cPixel[1] = ( tColor >> 16 ) & 0xFF;
|
|
cPixel[2] = ( tColor >> 8 ) & 0xFF;
|
|
cPixel[3] = tColor & 0xFF;
|
|
};
|
|
};
|
|
#else
|
|
if( cNode->values.cnt == 0 ) {
|
|
// Set Blue
|
|
cPixel[0] = 0x00;
|
|
cPixel[1] = 0x00;
|
|
cPixel[2] = 0xff;
|
|
cPixel[3] = 0xff;
|
|
} else {
|
|
uint32_t tColor;
|
|
float tVal = ((float) cNode->values.min ) / 4096.f;
|
|
tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
|
|
cPixel[0] = ( tColor >> 24 ) & 0xFF;
|
|
cPixel[1] = ( tColor >> 16 ) & 0xFF;
|
|
cPixel[2] = ( tColor >> 8 ) & 0xFF;
|
|
cPixel[3] = tColor & 0xFF;
|
|
};
|
|
#endif
|
|
};
|
|
};
|
|
};
|
|
|
|
sprintf( filename, "data/device_draws/%s_map.png", uid );
|
|
RetVal = stbi_write_png( filename, TH_LINE_NODES, Q_SCAN_COUNT, cSpace, tMemory, TH_LINE_NODES * cSpace );
|
|
free( tMemory );
|
|
if( RetVal == 0 ) return false;
|
|
return true;
|
|
};
|
|
*/
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|