ObjectDataAngular.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // Created by wrede on 19.05.16.
  3. //
  4. #include <opencv2/imgproc.hpp>
  5. #include <math.h>
  6. #include "ObjectDataAngular.h"
  7. #include "../util/MyMath.h"
  8. namespace core
  9. {
  10. ObjectDataAngular::ObjectDataAngular(size_t frame_index,
  11. const cv::Point2d& position,
  12. double angle)
  13. : ObjectData2D(frame_index, position), angle_(angle), angular_weight_(1.0)
  14. {
  15. }
  16. ObjectDataAngular::ObjectDataAngular(size_t frame_index,
  17. const cv::Point2d& position,
  18. double angle,
  19. double temporal_weight,
  20. double spatial_weight,
  21. double angular_weight)
  22. : ObjectData2D(frame_index, position)
  23. {
  24. angle_ = angle;
  25. angular_weight_ = angular_weight;
  26. SetTemporalWeight(temporal_weight);
  27. SetSpatialWeight(spatial_weight);
  28. }
  29. void ObjectDataAngular::SetAngularWeight(double weight)
  30. {
  31. angular_weight_ = weight;
  32. }
  33. double ObjectDataAngular::GetAngle() const
  34. {
  35. return angle_;
  36. }
  37. double ObjectDataAngular::GetAngularWeight() const
  38. {
  39. return angular_weight_;
  40. }
  41. double ObjectDataAngular::CompareTo(ObjectDataPtr obj) const
  42. {
  43. ObjectDataAngularPtr obj_ang =
  44. std::static_pointer_cast<ObjectDataAngular>(obj);
  45. double d_ang = std::abs(obj_ang->angle_ - angle_);
  46. return ObjectData2D::CompareTo(obj) + d_ang * angular_weight_;
  47. }
  48. ObjectDataPtr ObjectDataAngular::Interpolate(ObjectDataPtr obj,
  49. double fraction) const
  50. {
  51. ObjectData2DPtr obj_in =
  52. std::static_pointer_cast<ObjectData2D>(
  53. ObjectData2D::Interpolate(obj, fraction));
  54. ObjectDataAngularPtr obj_ang =
  55. std::static_pointer_cast<ObjectDataAngular>(obj);
  56. double angle = util::MyMath::Lerp(angle_, obj_ang->angle_, fraction);
  57. ObjectDataAngularPtr obj_out(
  58. new ObjectDataAngular(
  59. obj_in->GetFrameIndex(), obj_in->GetPosition(), angle));
  60. return obj_out;
  61. }
  62. void ObjectDataAngular::Visualize(cv::Mat& image, cv::Scalar& color) const
  63. {
  64. double x = GetPosition().x * image.cols;
  65. double y = GetPosition().y * image.rows;
  66. int r = (int) (0.005 * (image.rows + image.cols) * 0.5);
  67. double a_x = x + cos(angle_) * r * 6.0;
  68. double a_y = y + sin(angle_) * r * 6.0;
  69. cv::circle(image, cv::Point2d(x, y), r, color);
  70. cv::line(image, cv::Point2d(x, y), cv::Point2d(a_x, a_y), color);
  71. }
  72. void ObjectDataAngular::Print(std::ostream& os) const
  73. {
  74. os << "ObjectDataAngular{"
  75. << "f:" << GetFrameIndex() << ", "
  76. << "x:" << GetPosition().x << ", "
  77. << "y:" << GetPosition().y << ", "
  78. << "a:" << GetAngle() << "}";
  79. }
  80. }