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.

454 lines
18 KiB

5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
5 years ago
​
​
​
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
5 years ago
​
​
5 years ago
​
5 years ago
5 years ago
​
​
​
​
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
​
​
​
​
5 years ago
5 years ago
​
​
​
​
​
5 years ago
5 years ago
​
​
​
​
​
​
​
​
​
5 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
5 years ago
5 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "rgooseNodeSensor.h"
  2. #include <opencv2/opencv.hpp>
  3. #define LOG( X ) m_pLog->Log( "NODSEN", this, X )
  4. #define LOG_ERROR( X ) m_pLog->Log( "NODSEN", this, _LOG_ERROR, X )
  5. argusNodeSensor::argusNodeSensor( uint32_t id ):argusNetNode( id ),m_oPosition(){
  6. m_pLog = basicLogCollection::getInstance();
  7. m_pTargetFilter = NULL;
  8. };
  9. argusNodeSensor::argusNodeSensor( DBC_NODE_DATA *Data ):argusNetNode( Data ),m_oPosition(){
  10. m_pLog = basicLogCollection::getInstance();
  11. m_pTargetFilter = NULL;
  12. };
  13. argusNodeSensor::~argusNodeSensor(){
  14. };
  15. #define SKIP_LINE_PIXELS 28
  16. #define HEIGHT 512
  17. #define WIDTH 1024
  18. // scale factor -> 4/9
  19. bool argusNodeSensor::handleDeviceDraw( uint8_t kID, void *th_data, size_t th_size, bool byMinimum ){
  20. if( th_data == NULL ) return false;
  21. if( th_size == 0 ) return false;
  22. if( m_pDBC == NULL ) return false;
  23. //Clear Old Draw
  24. CSTR old = m_pDBC->getLRFDraw( getNodeID() );
  25. if ( old ) {
  26. // delete old draw
  27. char filename[256];
  28. sprintf( filename, "data/device_draws/%s_100.png", old );
  29. if( fileExist( filename ) ){
  30. unlink( filename );
  31. };
  32. sprintf( filename, "data/device_draws/%s_50.png", old );
  33. if( fileExist( filename ) ){
  34. unlink( filename );
  35. };
  36. sprintf( filename, "data/device_draws/%s_25.png", old );
  37. if( fileExist( filename ) ){
  38. unlink( filename );
  39. };
  40. sprintf( filename, "data/device_draws/%s_12.png", old );
  41. if( fileExist( filename ) ){
  42. unlink( filename );
  43. };
  44. sprintf( filename, "data/device_draws/%s_map.png", old );
  45. if( fileExist( filename ) ){
  46. unlink( filename );
  47. };
  48. free( old );
  49. };
  50. CSTR uid = getUniqID_MD5();
  51. if( uid == NULL ) return false;
  52. switch( getNodeType() ){
  53. case ARGUS_ALS_SENSOR:
  54. case ARGUS_LFS_SENSOR:
  55. case ARGUS_PLS_200_SENSOR:
  56. case ARGUS_PLS_360_SENSOR:
  57. case ARGUS_NET_PLS_200:{
  58. char * emptyBG = "data/assets/images/lfs_draw_empty_100.png";
  59. if ( fileExist( emptyBG ) ) {
  60. cv::Mat tImage = cv::imread( emptyBG, cv::IMREAD_UNCHANGED );
  61. if( tImage.rows != 512 || tImage.cols != 1024 ){
  62. LOG_ERROR( "Background Image wrong size (should be 1024x512)!" );
  63. free( uid );
  64. return false;
  65. };
  66. //m_pDBC->addLRFDraw( getNodeID(), TH_SIZE_NODES, uid, kID, 1, true );
  67. } else {
  68. LOG_ERROR( "Background Image is Not Found!" );
  69. free( uid );
  70. return false;
  71. };
  72. break;
  73. };
  74. case ARGUS_3D_SENSOR:{
  75. char * emptyBG = "data/assets/images/empty_3d.png";
  76. thresholdNode * ptr = (thresholdNode *) th_data;
  77. if ( fileExist( emptyBG ) ) {
  78. cv::Mat tImage = cv::imread( emptyBG, cv::IMREAD_UNCHANGED );
  79. if( tImage.rows != 512 || tImage.cols != 1024 ){
  80. LOG_ERROR( "Background Image wrong size (should be 1024x512)!" );
  81. free( uid );
  82. return false;
  83. };
  84. uint8_t * tMemory = tImage.data;
  85. thresholdNode * cNode = NULL;
  86. uint8_t * cPixel = NULL;
  87. int pix = 0;
  88. int mem = 0;
  89. bool s_bit = false;
  90. bool no_data = false;
  91. float tVal;
  92. bool master = ( kID < 16 );
  93. for( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
  94. if( ( idx % 4 ) == 0 ){
  95. mem++;
  96. if ( master ) {
  97. cNode = ptr + TH_SIZE_NODES - mem - 1;
  98. } else {
  99. cNode = ptr + mem - 1;
  100. };
  101. if( !s_bit ) s_bit = cNode->values.sbit;
  102. if( !no_data ) no_data = ( cNode->values.cnt == 0 );
  103. if( !s_bit && !no_data ){
  104. if( byMinimum ) {
  105. tVal = ((float)cNode->values.min) / 4096.f;
  106. } else {
  107. tVal = ((float)cNode->values.max) / 4096.f;
  108. };
  109. };
  110. };
  111. if( ( idx % 9 ) == 0 ){
  112. if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) {
  113. cPixel = tMemory + (pix << 2);
  114. pix++;
  115. if( s_bit ) { // Set Red
  116. cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff;
  117. } else {
  118. if( no_data ) { // Set Blue
  119. cPixel[0] = 0xff; cPixel[1] = 0x00; cPixel[2] = 0x00; cPixel[3] = 0xff;
  120. } else {
  121. uint32_t tColor;
  122. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  123. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  124. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  125. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  126. cPixel[3] = tColor & 0xFF;
  127. };
  128. };
  129. s_bit = false;
  130. no_data = false;
  131. };
  132. };
  133. };
  134. char filename[256];
  135. sprintf( filename, "data/device_draws/%s_100.png", uid );
  136. //int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace );
  137. vector<int> compression_params;
  138. compression_params.push_back( cv::IMWRITE_PNG_COMPRESSION );
  139. compression_params.push_back(9);
  140. if(! cv::imwrite( filename, tImage, compression_params ) ){
  141. tImage.release();
  142. free( uid );
  143. return false;
  144. };
  145. tImage.release();
  146. #ifdef DEBUG_EXTRA
  147. LOG("Draw Saved!");
  148. #endif
  149. cv::Mat tMap( Q_SCAN_COUNT, TH_LINE_NODES, CV_8UC4 );
  150. #ifdef DEBUG_EXTRA
  151. LOG("Map Creating");
  152. #endif
  153. tMemory = tMap.data;
  154. for( int j = 0; j < Q_SCAN_COUNT; j++ ){
  155. for( int i = 0; i < TH_LINE_NODES; i++ ){
  156. //cNode = ptr+(j*i);
  157. //cNode = &ptr[ ( TH_LINE_NODES * j ) + i ];
  158. int ids = 0;
  159. int idd = 0;
  160. if ( master ) {
  161. //cNode = ptr+makeIds( i, j , true );
  162. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  163. ids = makeIds( i, j , true );
  164. idd = 4 * makeIds( i, j , false );
  165. //cNode = ptr + ( i * j );
  166. //cPixel = tMemory + ( cSpace * i * j );
  167. } else {
  168. //cNode = ptr+makeIds( i, j , false );
  169. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  170. ids = makeIds( i, j , false );
  171. idd = 4 * makeIds( i, j , false );
  172. };
  173. cNode = ptr + ids ;
  174. cPixel = tMemory + idd;
  175. if( 0 ) { // Monochrome
  176. #ifdef CHECK_SUN_BIT
  177. if( cNode->values.sbit ) {
  178. cPixel[0] = 0;
  179. } else {
  180. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  181. };
  182. #else
  183. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  184. #endif
  185. } else {
  186. #ifdef CHECK_SUN_BIT
  187. if( cNode->values.sbit ) {
  188. // Set Red
  189. cPixel[0] = 0x00;
  190. cPixel[1] = 0x00;
  191. cPixel[2] = 0xff;
  192. cPixel[3] = 0xff;
  193. } else {
  194. if( cNode->values.cnt == 0 ) {
  195. // Set Blue
  196. cPixel[0] = 0xff;
  197. cPixel[1] = 0x00;
  198. cPixel[2] = 0x00;
  199. cPixel[3] = 0xff;
  200. } else {
  201. uint32_t tColor;
  202. float tVal = ((float) cNode->values.min ) / 4096.f;
  203. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  204. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  205. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  206. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  207. cPixel[3] = tColor & 0xFF;
  208. };
  209. };
  210. #else
  211. if( cNode->values.cnt == 0 ) {
  212. // Set Blue
  213. cPixel[0] = 0xff;
  214. cPixel[1] = 0x00;
  215. cPixel[2] = 0x00;
  216. cPixel[3] = 0xff;
  217. } else {
  218. uint32_t tColor;
  219. float tVal = ((float) cNode->values.min ) / 4096.f;
  220. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  221. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  222. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  223. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  224. cPixel[3] = tColor & 0xFF;
  225. };
  226. #endif
  227. };
  228. };
  229. };
  230. sprintf( filename, "data/device_draws/%s_map.png", uid );
  231. LOG(filename);
  232. if(! cv::imwrite( filename, tMap, compression_params ) ){
  233. tMap.release();
  234. free( uid );
  235. return false;
  236. };
  237. tMap.release();
  238. m_pDBC->addLRFDraw( getNodeID(), TH_SIZE_NODES, uid, kID, 1, true );
  239. } else {
  240. LOG_ERROR( "Background Image is Not Found!" );
  241. free( uid );
  242. return false;
  243. };
  244. break;
  245. };
  246. };
  247. free( uid );
  248. return true;
  249. };
  250. /*
  251. #define STB_IMAGE_IMPLEMENTATION
  252. #include "../data/stbi/stb_image.h"
  253. #define STB_IMAGE_WRITE_IMPLEMENTATION
  254. #include "../data/stbi/stb_image_write.h"
  255. #undef STB_IMAGE_WRITE_IMPLEMENTATION
  256. #undef STB_IMAGE_IMPLEMENTATION
  257. bool argus3DLIDAR::saveTHPicture( thresholdNode *ptr, CSTR uid, bool master, bool byMinimum, bool monochrome ){
  258. uint8_t *tMemory = NULL;
  259. thresholdNode *cNode = NULL;
  260. uint8_t *cPixel = NULL;
  261. int cSpace;
  262. int x, y;
  263. tMemory = stbi_load( "data/assets/images/empty_3d.png", &x, &y, &cSpace, STBI_default );
  264. if( tMemory == NULL ){
  265. LOG_ERROR("Draw Memory Alloc Eror!");
  266. return false;
  267. };
  268. if( x != 1024 || y != 512 ){
  269. LOG("Wrong IMG Size!");
  270. free( tMemory );
  271. return NULL;
  272. };
  273. int pix = 0;
  274. int mem = 0;
  275. bool s_bit = false;
  276. bool no_data = false;
  277. float tVal;
  278. for ( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
  279. if( ( idx % 4 ) == 0 ){
  280. mem++;
  281. if ( master ) {
  282. cNode = ptr + TH_SIZE_NODES - mem - 1;
  283. } else {
  284. cNode = ptr + mem - 1;
  285. };
  286. if( !s_bit ) s_bit = cNode->values.sbit;
  287. if( !no_data ) no_data = ( cNode->values.cnt == 0 );
  288. if( !s_bit && !no_data ){
  289. if( byMinimum ) {
  290. tVal = ((float)cNode->values.min) / 4096.f;
  291. } else {
  292. tVal = ((float)cNode->values.max) / 4096.f;
  293. };
  294. };
  295. };
  296. if( ( idx % 9 ) == 0 ){
  297. if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) {
  298. cPixel = tMemory + (pix << 2);
  299. pix++;
  300. if( s_bit ) { // Set Red
  301. cPixel[0] = 0x00; cPixel[1] = 0xff; cPixel[2] = 0x00; cPixel[3] = 0xff;
  302. } else {
  303. if( no_data ) { // Set Blue
  304. cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff;
  305. } else {
  306. uint32_t tColor;
  307. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  308. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  309. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  310. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  311. cPixel[3] = tColor & 0xFF;
  312. };
  313. };
  314. s_bit = false;
  315. no_data = false;
  316. }
  317. };
  318. };
  319. char filename[256];
  320. sprintf( filename, "data/device_draws/%s_100.png", uid );
  321. int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace );
  322. free( tMemory );
  323. if( RetVal == 0 ) return false;
  324. if( monochrome ) {
  325. cSpace = 1;
  326. } else {
  327. cSpace = 4;
  328. };
  329. tMemory = (uint8_t *) malloc( TH_SIZE_NODES * cSpace );
  330. if( tMemory == NULL ){
  331. LOG_ERROR("Map Memory Alloc Eror!");
  332. return false;
  333. };
  334. for (int j = 0; j < Q_SCAN_COUNT; j++) {
  335. for ( int i = 0; i < TH_LINE_NODES; i++ ) {
  336. //cNode = ptr+(j*i);
  337. //cNode = &ptr[ ( TH_LINE_NODES * j ) + i ];
  338. int ids = 0;
  339. int idd = 0;
  340. if ( master ) {
  341. //cNode = ptr+makeIds( i, j , true );
  342. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  343. ids = makeIds( i, j , true );
  344. idd = cSpace * makeIds( i, j , false );
  345. //cNode = ptr + ( i * j );
  346. //cPixel = tMemory + ( cSpace * i * j );
  347. } else {
  348. //cNode = ptr+makeIds( i, j , false );
  349. //cPixel = tMemory+( cSpace * makeIds( i, j , false ));
  350. ids = makeIds( i, j , false );
  351. idd = cSpace * makeIds( i, j , false );
  352. };
  353. cNode = ptr + ids ;
  354. cPixel = tMemory + idd;
  355. if( monochrome ) {
  356. #ifdef CHECK_SUN_BIT
  357. if( cNode->values.sbit ) {
  358. cPixel[0] = 0;
  359. } else {
  360. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  361. };
  362. #else
  363. cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f );
  364. #endif
  365. } else {
  366. #ifdef CHECK_SUN_BIT
  367. if( cNode->values.sbit ) {
  368. // Set Red
  369. cPixel[0] = 0x00;
  370. cPixel[1] = 0xff;
  371. cPixel[2] = 0x00;
  372. cPixel[3] = 0xff;
  373. } else {
  374. if( cNode->values.cnt == 0 ) {
  375. // Set Blue
  376. cPixel[0] = 0x00;
  377. cPixel[1] = 0x00;
  378. cPixel[2] = 0xff;
  379. cPixel[3] = 0xff;
  380. } else {
  381. uint32_t tColor;
  382. float tVal = ((float) cNode->values.min ) / 4096.f;
  383. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  384. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  385. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  386. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  387. cPixel[3] = tColor & 0xFF;
  388. };
  389. };
  390. #else
  391. if( cNode->values.cnt == 0 ) {
  392. // Set Blue
  393. cPixel[0] = 0x00;
  394. cPixel[1] = 0x00;
  395. cPixel[2] = 0xff;
  396. cPixel[3] = 0xff;
  397. } else {
  398. uint32_t tColor;
  399. float tVal = ((float) cNode->values.min ) / 4096.f;
  400. tColor = interpolate( 0x000000ff, 0xffffffff, tVal );
  401. cPixel[0] = ( tColor >> 24 ) & 0xFF;
  402. cPixel[1] = ( tColor >> 16 ) & 0xFF;
  403. cPixel[2] = ( tColor >> 8 ) & 0xFF;
  404. cPixel[3] = tColor & 0xFF;
  405. };
  406. #endif
  407. };
  408. };
  409. };
  410. sprintf( filename, "data/device_draws/%s_map.png", uid );
  411. RetVal = stbi_write_png( filename, TH_LINE_NODES, Q_SCAN_COUNT, cSpace, tMemory, TH_LINE_NODES * cSpace );
  412. free( tMemory );
  413. if( RetVal == 0 ) return false;
  414. return true;
  415. };
  416. */
  417. #undef LOG
  418. #undef LOG_ERROR