SourceXtractorPlusPlus
0.21
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
SEImplementation
src
lib
Plugin
MeasurementFrameRectangle
MeasurementFrameRectangleTask.cpp
Go to the documentation of this file.
1
17
/*
18
* MeasurementFrameRectangleTask.cpp
19
*
20
* Created on: Sep 24, 2018
21
* Author: Alejandro Alvarez Ayllon
22
*/
23
#include <iostream>
24
25
#include <
SEImplementation/Plugin/MeasurementFrameCoordinates/MeasurementFrameCoordinates.h
>
26
#include <
SEImplementation/Plugin/MeasurementFrameInfo/MeasurementFrameInfo.h
>
27
#include <
SEImplementation/Plugin/PixelBoundaries/PixelBoundaries.h
>
28
#include "
SEImplementation/Plugin/DetectionFrameCoordinates/DetectionFrameCoordinates.h
"
29
30
#include <
SEImplementation/Plugin/MeasurementFrameRectangle/MeasurementFrameRectangle.h
>
31
#include <
SEImplementation/Plugin/MeasurementFrameRectangle/MeasurementFrameRectangleTask.h
>
32
33
namespace
SourceXtractor
{
34
35
void
MeasurementFrameRectangleTask::computeProperties
(
SourceInterface
&
source
)
const
{
36
auto
&
detection_group_stamp
=
source
.getProperty<
PixelBoundaries
>();
37
auto
measurement_frame_coordinates
=
source
.getProperty<
MeasurementFrameCoordinates
>(
m_instance
).getCoordinateSystem();
38
auto
detection_frame_coordinates
=
source
.getProperty<
DetectionFrameCoordinates
>().getCoordinateSystem();
39
40
const
auto
&
measurement_frame_info
=
source
.getProperty<
MeasurementFrameInfo
>(
m_instance
);
41
42
// Get the coordinates of the detection frame group stamp
43
auto
stamp_top_left
=
detection_group_stamp
.getMin();
44
auto
width =
detection_group_stamp
.getWidth();
45
auto
height =
detection_group_stamp
.getHeight();
46
47
// Transform the 4 corner coordinates from detection image
48
ImageCoordinate
coord1
,
coord2
,
coord3
,
coord4
;
49
bool
bad_coordinates
=
false
;
50
try
{
51
coord1
=
measurement_frame_coordinates
->worldToImage(
52
detection_frame_coordinates
->imageToWorld(
ImageCoordinate
(
stamp_top_left
.m_x,
stamp_top_left
.m_y)));
53
coord2
=
measurement_frame_coordinates
->worldToImage(
54
detection_frame_coordinates
->imageToWorld(
ImageCoordinate
(
stamp_top_left
.m_x + width,
stamp_top_left
.m_y)));
55
coord3
=
measurement_frame_coordinates
->worldToImage(
56
detection_frame_coordinates
->imageToWorld(
ImageCoordinate
(
stamp_top_left
.m_x + width,
stamp_top_left
.m_y + height)));
57
coord4
=
measurement_frame_coordinates
->worldToImage(
58
detection_frame_coordinates
->imageToWorld(
ImageCoordinate
(
stamp_top_left
.m_x,
stamp_top_left
.m_y + height)));
59
}
60
catch
(
const
InvalidCoordinatesException
&) {
61
bad_coordinates
=
true
;
62
}
63
64
// Determine the min/max coordinates
65
auto
min_x
=
std::min
(
coord1
.m_x,
std::min
(
coord2
.m_x,
std::min
(
coord3
.m_x,
coord4
.m_x)));
66
auto
min_y
=
std::min
(
coord1
.m_y,
std::min
(
coord2
.m_y,
std::min
(
coord3
.m_y,
coord4
.m_y)));
67
auto
max_x
=
std::max
(
coord1
.m_x,
std::max
(
coord2
.m_x,
std::max
(
coord3
.m_x,
coord4
.m_x)));
68
auto
max_y
=
std::max
(
coord1
.m_y,
std::max
(
coord2
.m_y,
std::max
(
coord3
.m_y,
coord4
.m_y)));
69
70
PixelCoordinate
min_coord
,
max_coord
;
71
min_coord
.m_x =
int
(
min_x
);
72
min_coord
.m_y =
int
(
min_y
);
73
max_coord
.m_x =
int
(
max_x
) + 1;
74
max_coord
.m_y =
int
(
max_y
) + 1;
75
76
// The full boundaries may lie outside of the frame
77
if
(
bad_coordinates
||
max_coord
.m_x < 0 ||
max_coord
.m_y < 0 ||
78
min_coord
.m_x >=
measurement_frame_info
.getWidth() ||
min_coord
.m_y >=
measurement_frame_info
.getHeight()) {
79
source
.setIndexedProperty<
MeasurementFrameRectangle
>(
m_instance
,
bad_coordinates
);
80
}
81
// Clip the coordinates to fit the available image
82
else
{
83
min_coord
.m_x =
std::max
(0,
min_coord
.m_x);
84
min_coord
.m_y =
std::max
(0,
min_coord
.m_y);
85
max_coord
.m_x =
std::min
(
measurement_frame_info
.getWidth() - 1,
max_coord
.m_x);
86
max_coord
.m_y =
std::min
(
measurement_frame_info
.getHeight() - 1,
max_coord
.m_y);
87
88
source
.setIndexedProperty<
MeasurementFrameRectangle
>(
m_instance
,
min_coord
,
max_coord
);
89
}
90
}
91
92
}
// SEImplementation namespace
93
DetectionFrameCoordinates.h
MeasurementFrameCoordinates.h
MeasurementFrameInfo.h
MeasurementFrameRectangleTask.h
MeasurementFrameRectangle.h
PixelBoundaries.h
SourceXtractor::DetectionFrameCoordinates
Definition
DetectionFrameCoordinates.h:26
SourceXtractor::InvalidCoordinatesException
Definition
CoordinateSystem.h:62
SourceXtractor::MeasurementFrameCoordinates
Definition
MeasurementFrameCoordinates.h:26
SourceXtractor::MeasurementFrameInfo
Definition
MeasurementFrameInfo.h:28
SourceXtractor::MeasurementFrameRectangleTask::computeProperties
void computeProperties(SourceInterface &source) const override
Computes one or more properties for the Source.
Definition
MeasurementFrameRectangleTask.cpp:35
SourceXtractor::MeasurementFrameRectangleTask::m_instance
unsigned m_instance
Definition
MeasurementFrameRectangleTask.h:42
SourceXtractor::MeasurementFrameRectangle
Definition
MeasurementFrameRectangle.h:34
SourceXtractor::PixelBoundaries
The bounding box of all the pixels in the source. Both min and max coordinate are inclusive.
Definition
PixelBoundaries.h:37
SourceXtractor::SourceInterface
The SourceInterface is an abstract "source" that has properties attached to it.
Definition
SourceInterface.h:46
std::function
std::max
T max(T... args)
std::min
T min(T... args)
SourceXtractor
Definition
Aperture.h:30
SourceXtractor::ImageCoordinate
Definition
CoordinateSystem.h:43
SourceXtractor::PixelCoordinate
A pixel coordinate made of two integers m_x and m_y.
Definition
PixelCoordinate.h:37
Generated by
1.10.0