main.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include <QCoreApplication>
  2. #include <QImage>
  3. #include <QJsonObject>
  4. #include <QJsonArray>
  5. #include <QJsonDocument>
  6. #include <imt/EIMBase.h>
  7. #include <imt/EIMResult.h>
  8. #include <imt/CEIMResult.h>
  9. #include <imt/scale.h>
  10. #include <iostream>
  11. using namespace std;
  12. const CScale *g_pCurrentScale;
  13. // ./math -platform offscreen -image=../storage/media/15/a0fd44eb-8174-4d8b-bc76-690bc6e441b3.jpeg -metric=0.3x0.3 -point1=280x259 -point2=411x255
  14. int main(int argc, char *argv[])
  15. {
  16. QCoreApplication app(argc, argv);
  17. QImage image;
  18. double pixelWidth = 0, pixelHeight = 0;
  19. Point m_p0, m_p1;
  20. // parse cmd line
  21. foreach(QString arg, QCoreApplication::arguments()) {
  22. if(arg.startsWith("-image=")) {
  23. QString path = arg.replace("-image=", "");
  24. if(!image.load(path)) {
  25. return -2;
  26. }
  27. }
  28. else if(arg.startsWith("-metric=")) {
  29. QStringList metric = arg.replace("-metric=", "").split("x");
  30. if(metric.size()==2) {
  31. pixelWidth = metric[0].toDouble();
  32. pixelHeight = metric[1].toDouble();
  33. }
  34. else {
  35. return -1;
  36. }
  37. }
  38. else if(arg.startsWith("-point1=")) {
  39. QStringList point = arg.replace("-point1=", "").split("x");
  40. if(point.size()==2) {
  41. m_p0.x = point[0].toInt();
  42. m_p0.y = point[1].toInt();
  43. }
  44. else {
  45. return -4;
  46. }
  47. }
  48. else if(arg.startsWith("-point2=")) {
  49. QStringList point = arg.replace("-point2=", "").split("x");
  50. if(point.size()==2) {
  51. m_p1.x = point[0].toInt();
  52. m_p1.y = point[1].toInt();
  53. }
  54. else {
  55. return -5;
  56. }
  57. }
  58. }
  59. if(image.isNull() || pixelWidth==0.0 || pixelWidth==0.0) {
  60. return -3;
  61. }
  62. //std::cout << image.width() << "x" << image.height() << std::endl;
  63. //std::cout << pixelWidth << "x" << pixelHeight << std::endl;
  64. // [@DF] CScale complains (and abort) if metrics is not ortho lol
  65. double avg = (pixelWidth + pixelHeight) / 2.0;
  66. pixelWidth = pixelHeight = avg;
  67. g_pCurrentScale = new CScale("DLL scale", pixelWidth, pixelHeight);
  68. CEIMResult result;
  69. CEIMBase ceim;
  70. ceim.SetEimAssisted( true );
  71. bool status = ceim.Measure(&image, m_p0, m_p1, false, &result);
  72. result.result->p0.x = m_p0.x;
  73. result.result->p0.y = m_p0.y;
  74. result.result->p1.x = m_p1.x;
  75. result.result->p1.y = m_p1.y;
  76. result.result->distance = g_pCurrentScale->Distance( result.result->numberOfPoints );
  77. imt::IMTResult result2;
  78. status |= result.fill( &result2 );
  79. if(status) {
  80. QJsonObject data;
  81. data["nearWall"] = ceim.m_bNearWall;
  82. data["imt_max"] = result2.imt_max;
  83. data["imt_mean"] = result2.imt_mean;
  84. data["imt_stddev"] = result2.imt_standardDeviation;
  85. data["intima_mean"] = result2.intima_mean;
  86. data["media_mean"] = result2.media_mean;
  87. data["qualityIndex"] = result2.qualityIndex;
  88. data["distance"] = result2.distance;
  89. data["numberOfPoints"] = result2.numberOfPoints;
  90. QJsonArray vect_intima;
  91. QJsonArray vect_media;
  92. QJsonArray vect_adventitia;
  93. QJsonObject point;
  94. for (int i=0; i<result2.numberOfPoints; i++) {
  95. if(result2.vect_intima[i].x>0) {
  96. point["x"] = result2.vect_intima[i].x;
  97. point["y"] = result2.vect_intima[i].y;
  98. vect_intima.append(point);
  99. }
  100. if(result2.vect_media[i].x>0) {
  101. point["x"] = result2.vect_media[i].x;
  102. point["y"] = result2.vect_media[i].y;
  103. vect_media.append(point);
  104. }
  105. if(result2.vect_adventitia[i].x>0) {
  106. point["x"] = result2.vect_adventitia[i].x;
  107. point["y"] = result2.vect_adventitia[i].y;
  108. vect_adventitia.append(point);
  109. }
  110. }
  111. data["vect_intima"] = vect_intima;
  112. data["vect_media"] = vect_media;
  113. data["vect_adventitia"] = vect_adventitia;
  114. QString json = QJsonDocument(data).toJson(QJsonDocument::Compact);
  115. std::cout << json.toStdString() << std::endl;
  116. }
  117. return 0;
  118. }