Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions SEFramework/SEFramework/CoordinateSystem/CoordinateSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ struct ImageCoordinate {

ImageCoordinate() : m_x(0), m_y(0) {}
ImageCoordinate(double x, double y) : m_x(x), m_y(y) {}

ImageCoordinate operator*(double scalar) const {
return ImageCoordinate(m_x * scalar, m_y * scalar);
}

ImageCoordinate operator+(const ImageCoordinate& other) const {
return ImageCoordinate(m_x + other.m_x, m_y + other.m_y);
}

ImageCoordinate& operator+=(const ImageCoordinate& other) {
m_x += other.m_x;
m_y += other.m_y;
return *this;
}

ImageCoordinate operator-(const ImageCoordinate& other) const {
return ImageCoordinate(m_x - other.m_x, m_y - other.m_y);
}

ImageCoordinate& operator-=(const ImageCoordinate& other) {
m_x -= other.m_x;
m_y -= other.m_y;
return *this;
}
};

class CoordinateSystem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
#ifndef _SEIMPLEMENTATION_PLUGIN_MEASUREMENTFRAMERECTANGLE_MEASUREMENTFRAMERECTANGLE_H_
#define _SEIMPLEMENTATION_PLUGIN_MEASUREMENTFRAMERECTANGLE_MEASUREMENTFRAMERECTANGLE_H_

#include <tuple>

#include "SEUtils/PixelRectangle.h"
#include "SEFramework/CoordinateSystem/CoordinateSystem.h"

#include "SEFramework/Property/Property.h"
#include "SEFramework/Image/Image.h"
Expand All @@ -36,11 +39,15 @@ class MeasurementFrameRectangle: public Property {
virtual ~MeasurementFrameRectangle() = default;

explicit MeasurementFrameRectangle(bool bad_projection):
m_min_coord{-1, -1}, m_max_coord{-1, -1}, m_bad_projection{bad_projection}{}
m_min_coord{-1, -1}, m_max_coord{-1, -1}, m_min_coord_image{-1, -1},
m_max_coord_image{-1, -1}, m_bad_projection{bad_projection} {}

MeasurementFrameRectangle(PixelCoordinate min_coord, PixelCoordinate max_coord):
m_min_coord{min_coord}, m_max_coord{max_coord}, m_bad_projection{false} {
MeasurementFrameRectangle(PixelCoordinate min_coord, PixelCoordinate max_coord,
ImageCoordinate min_coord_image, ImageCoordinate max_coord_image):
m_min_coord(min_coord), m_max_coord(max_coord),
m_min_coord_image(min_coord_image), m_max_coord_image(max_coord_image), m_bad_projection{false} {
assert(min_coord.m_x <= max_coord.m_x && min_coord.m_y <= max_coord.m_y);
assert(min_coord_image.m_x <= max_coord_image.m_x && min_coord_image.m_y <= max_coord_image.m_y);
}

PixelCoordinate getTopLeft() const {
Expand All @@ -65,8 +72,8 @@ class MeasurementFrameRectangle: public Property {
return m_max_coord.m_y - m_min_coord.m_y + 1;
}

PixelRectangle getRect() const {
return PixelRectangle(m_min_coord, m_max_coord);
std::tuple<ImageCoordinate, ImageCoordinate> getImageRect() const {
return std::make_tuple(m_min_coord_image, m_max_coord_image);
}

bool badProjection() const {
Expand All @@ -75,6 +82,7 @@ class MeasurementFrameRectangle: public Property {

private:
PixelCoordinate m_min_coord, m_max_coord;
ImageCoordinate m_min_coord_image, m_max_coord_image;
bool m_bad_projection;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ FlexibleModelFittingIterativeTask::~FlexibleModelFittingIterativeTask() {
}

PixelRectangle FlexibleModelFittingIterativeTask::getUnclippedFittingRect(SourceInterface& source, int frame_index) const {
auto fitting_rect = source.getProperty<MeasurementFrameRectangle>(frame_index).getRect();
ImageCoordinate min_coord, max_coord;
std::tie(min_coord, max_coord) = source.getProperty<MeasurementFrameRectangle>(frame_index).getImageRect();

if (m_window_type == WindowType::ROTATED_ELLIPSE) {
auto ellipse = getFittingEllipse(source, frame_index);
Expand All @@ -84,14 +85,14 @@ PixelRectangle FlexibleModelFittingIterativeTask::getUnclippedFittingRect(Source
return getEllipseRect(ellipse);
}

if (fitting_rect.getWidth() <= 0 || fitting_rect.getHeight() <= 0) {
if (max_coord.m_x - min_coord.m_x <= 0 || max_coord.m_y - min_coord.m_y <= 0) {
return PixelRectangle();
} else {
auto min = fitting_rect.getTopLeft();
auto max = fitting_rect.getBottomRight();
auto min = min_coord;
auto max = max_coord;

// FIXME temporary, for now just enlarge the area by a fixed amount of pixels
PixelCoordinate border = (max - min) * .8 + PixelCoordinate(2, 2);
ImageCoordinate border = (max - min) * .8 + ImageCoordinate(2.0, 2.0);

min -= border;
max += border;
Expand Down Expand Up @@ -125,7 +126,10 @@ PixelRectangle FlexibleModelFittingIterativeTask::getUnclippedFittingRect(Source
max.m_y = min.m_y + size;
}

return PixelRectangle(min, max);
auto min_pc = PixelCoordinate(static_cast<int>(min.m_x + 0.5), static_cast<int>(min.m_y + 0.5));
auto max_pc = PixelCoordinate(static_cast<int>(max.m_x + 0.5), static_cast<int>(max.m_y + 0.5));

return PixelRectangle(min_pc, max_pc);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ void MeasurementFrameRectangleTask::computeProperties(SourceInterface& source) c
max_coord.m_x = std::min(measurement_frame_info.getWidth() - 1, max_coord.m_x);
max_coord.m_y = std::min(measurement_frame_info.getHeight() - 1, max_coord.m_y);

source.setIndexedProperty<MeasurementFrameRectangle>(m_instance, min_coord, max_coord);
source.setIndexedProperty<MeasurementFrameRectangle>(
m_instance, min_coord, max_coord, ImageCoordinate(min_x, min_y), ImageCoordinate(max_x, max_y));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "SEImplementation/Plugin/DetectionFrameCoordinates/DetectionFrameCoordinates.h"
#include <SEImplementation/Plugin/WorldCentroid/WorldCentroid.h>
#include <SEImplementation/Plugin/AssocMode/AssocMode.h>
#include <SEImplementation/Plugin/ReferenceCoordinates/ReferenceCoordinates.h>

#include <SEImplementation/Plugin/MeasurementFrameRectangle/MeasurementFrameRectangle.h>
#include <SEImplementation/Plugin/MeasurementFrameRectangle/MeasurementFrameRectangleTaskNoDetect.h>
Expand All @@ -31,23 +32,27 @@ namespace SourceXtractor {

void MeasurementFrameRectangleTaskNoDetect::computeProperties(SourceInterface& source) const {
auto measurement_frame_coordinates = source.getProperty<MeasurementFrameCoordinates>(m_instance).getCoordinateSystem();
auto reference_frame_coordinates = source.getProperty<ReferenceCoordinates>().getCoordinateSystem();

const auto& measurement_frame_info = source.getProperty<MeasurementFrameInfo>(m_instance);
const auto& world_centroid = source.getProperty<WorldCentroid>();
const auto& assoc_mode = source.getProperty<AssocMode>();

auto coord = world_centroid.getCentroid();

bool bad_coordinates = false;
ImageCoordinate coord1, coord2, coord3, coord4;
try {
int w = assoc_mode.getRefFramePixelWidth();
int h = assoc_mode.getRefFramePixelHeight();
auto w = assoc_mode.getRefFramePixelWidth();
auto h = assoc_mode.getRefFramePixelHeight();

auto c = measurement_frame_coordinates->worldToImage(coord);
coord1 = ImageCoordinate(c.m_x - w, c.m_y - h);
coord2 = ImageCoordinate(c.m_x + w, c.m_y - h);
coord3 = ImageCoordinate(c.m_x - w, c.m_y + h);
coord4 = ImageCoordinate(c.m_x + w, c.m_y + h);
auto c = reference_frame_coordinates->worldToImage(world_centroid.getCentroid());
coord1 = measurement_frame_coordinates->worldToImage(
reference_frame_coordinates->imageToWorld(ImageCoordinate(c.m_x - w, c.m_y - h)));
coord2 = measurement_frame_coordinates->worldToImage(
reference_frame_coordinates->imageToWorld(ImageCoordinate(c.m_x + w, c.m_y - h)));
coord3 = measurement_frame_coordinates->worldToImage(
reference_frame_coordinates->imageToWorld(ImageCoordinate(c.m_x - w, c.m_y + h)));
coord4 = measurement_frame_coordinates->worldToImage(
reference_frame_coordinates->imageToWorld(ImageCoordinate(c.m_x + w, c.m_y + h)));
}
catch (const InvalidCoordinatesException&) {
bad_coordinates = true;
Expand Down Expand Up @@ -77,7 +82,8 @@ void MeasurementFrameRectangleTaskNoDetect::computeProperties(SourceInterface& s
max_coord.m_x = std::min(measurement_frame_info.getWidth() - 1, max_coord.m_x);
max_coord.m_y = std::min(measurement_frame_info.getHeight() - 1, max_coord.m_y);

source.setIndexedProperty<MeasurementFrameRectangle>(m_instance, min_coord, max_coord);
source.setIndexedProperty<MeasurementFrameRectangle>(
m_instance, min_coord, max_coord, ImageCoordinate(min_x, min_y), ImageCoordinate(max_x, max_y));
}
}

Expand Down