54#include <opencv2/core/core.hpp>
55#define INVT_TYPEDEF_INT64
56#define INVT_TYPEDEF_UINT64
58#include <opencv2/video/tracking.hpp>
149 "with 0 at the top of the frame). Adjust this depending on the tilt angle of your camera "
150 "and video input resolution.",
155 "values means support line is below horizon line.",
177 public jevois::Parameter<roadfinder::horizon, roadfinder::support,
178 roadfinder::spacing, roadfinder::distthresh>
238 std::vector<Point2D<int> >
242 std::vector<Point2D<int> >
244 std::vector<uint>& startIndexes);
247 std::vector<Point2D<int> >
251 Line findLine2(
Segment const & s, cv::Mat
const & edgeMap, std::list<Segment>
const & supportingSegments,
252 std::vector<bool> & is_used,
float & totalLength,
uint & numSegments);
256 int const width,
int const height);
268 int const width,
int const height);
275 std::vector<Line>
combine(std::vector<Line> & prevLines, std::vector<Line>
const & currentLines,
276 int width,
int height);
unsigned int uint
Canonical unsigned int.
This is a basic class to encode 2D integer coordinates.
Navigation by finding road.
void trackVanishingLines(cv::Mat const &edgeMap, std::vector< Line > ¤tLines, jevois::RawImage &visual)
track vanishing lines by to fit to the new, inputted, edgemap
std::vector< VanishingPoint > itsVanishingPoints
vanishing points being considered
std::vector< Segment > itsCurrentSegments
current segments found using CVHoughlines
Point2D< float > computeRoadCenterPoint(cv::Mat const &edgeMap, std::vector< Line > &lines, Point2D< int > &vanishing_point, Point2D< float > &road_center_point, float &confidence)
computes the road center point to servo to
void process(cv::Mat const &img, jevois::RawImage &visual)
Compute the vanishing point location using the full blown algorithm.
std::vector< Line > computeVanishingLines(cv::Mat const &edgeMap, Point2D< int > const &vanishingPoint, jevois::RawImage &visual)
main function to detect the road
std::vector< Point2D< int > > getPixels(Point2D< int > const &p1, Point2D< int > const &p2, cv::Mat const &edgeMap)
get pixels for segment defined by p1 and p2 have added complexity to search within 1....
std::pair< Point2D< int >, float > getCurrVanishingPoint() const
Get the current vanishing point and confidence.
std::vector< Line > combine(std::vector< Line > &prevLines, std::vector< Line > const ¤tLines, int width, int height)
combine two lines sets, discard duplicates and overlaps
int itsCurrentMessageID
for visualizer
std::vector< Point2D< int > > getPixelsQuick(Point2D< int > const &p1, Point2D< int > const &p2, cv::Mat const &edgeMap)
get pixels that make up the segment defined by p1 and p2
Point2D< float > itsTargetPoint
target servo point
JEVOIS_DECLARE_PARAMETER(support, int, "Offset (in pixels) between horizon line and horizon support line (positive " "values means support line is below horizon line.", 20, ParamCateg)
Parameter.
std::mutex itsTrackMtx
locking line trackers vars
std::mutex itsAccTrajMtx
locking accunulated trajectory
void resetRoadModel()
Reset all tracker internals and start fresh (e.g., when changing goal direction)
Point2D< float > getCurrCenterPoint() const
Get the current road center point.
void projectForwardVanishingLines(std::vector< Line > &lines, std::vector< cv::Mat > const &edgeMaps, jevois::RawImage &visual)
update the lines with the inputted set of edgemaps
void updateRoadModel(std::vector< Line > &lines, int index)
update road model and incoming lines NOTE: also change the line parameters to sync them this avoids d...
Point2D< int > getVanishingPoint(std::vector< Line > const &lines, float &confidence)
estimate the vanishing point from the tracked lines
double itsRoadHeading
the current road heading
float getLineFitness(Point2D< int > const &horizonPoint, Point2D< int > const &roadBottomPoint, cv::Mat const &edgeMap, jevois::RawImage &visual)
compute how well the line equation fit the edgels in edgemap
Line findLine2(Segment const &s, cv::Mat const &edgeMap, std::list< Segment > const &supportingSegments, std::vector< bool > &is_used, float &totalLength, uint &numSegments)
find lines given the found supporting segments
std::vector< Line > itsCurrentLines
the current lines being tracked
JEVOIS_DECLARE_PARAMETER(spacing, unsigned int, "Spacing between vanishing point candidates (pixels).", 20, ParamCateg)
Parameter.
uint itsNumIdentifiedLines
indicate how many unique lines have been identified NOTE: never reset
void preUninit() override
This class has state and does not support some online param changes.
Point2D< int > itsVanishingPoint
current vanishing point
cv::KalmanFilter itsTPXfilter
virtual ~RoadFinder()
desctructor
void computeHoughSegments(cv::Mat const &cvImage)
compute the hough segments in the image
void fitLine(std::vector< Point2D< int > > const &points, Point2D< float > &p1, Point2D< float > &p2, int const width, int const height)
openCV wrapper function to fit a line to an input vector of points
JEVOIS_DECLARE_PARAMETER(distthresh, unsigned int, "Vanishing point distance threshold (pixels).", 40, ParamCateg)
Parameter.
std::vector< bool > itsVanishingPointStability
vanishing point score tracker
Point2D< float > itsAccumulatedTrajectory
the accumulated trajectory
void postInit() override
This class has state and does not support some online param changes.
bool itsTrackingFlag
indicate whether tracking
float itsVanishingPointConfidence
current vanishing point
Point2D< float > getCurrTargetPoint() const
Get the current target point.
JEVOIS_DECLARE_PARAMETER(horizon, int, "Estimated vertical (Y) position of the horizon (pixels, " "with 0 at the top of the frame). Adjust this depending on the tilt angle of your camera " "and video input resolution.", 70, ParamCateg)
Parameter.
void updateLine(Line &l, std::vector< Point2D< int > > const &points, float score, int const width, int const height)
update the information in by updating the input points, score and various handy coordinate locations
Point2D< float > itsCenterPoint
current center of road point
float getFilteredTargetX() const
Get the kalman-fitered target X, can be used to set robot steering.
std::vector< Line > discardDuplicates(std::vector< Line > const ¤tLines)
discard duplicate lines in a set
keeps all the ready to use information of a supporting line as it pertains to describing the road
std::vector< float > scores
tracking information to monitor health of the line
std::vector< float > start_scores
Point2D< float > onScreenRoadBottomPoint
Point2D< float > onScreenHorizonSupportPoint
Point2D< float > horizonPoint
quick information for various locations with respect to the road
Point2D< float > onScreenHorizonPoint
bool isActive
tracks whether the line can be used for finding the road center
std::vector< Point2D< int > > points
the points that are fit to the line
Point2D< float > roadBottomPoint
float length
basic information to specify the line
std::vector< Segment > segments
original supporting segments out of sync after initial frame
Point2D< float > pointToServo
Point2D< float > horizonSupportPoint
Store information about the road.
std::vector< Point2D< float > > lastSeenHorizonPoint
std::vector< Line > lines
std::vector< Point2D< float > > lastSeenLocation
std::vector< int > numMatches
std::vector< int > lastActiveIndex
a segment is defined by the two end-points
Segment(Point2D< int > in_p1, Point2D< int > in_p2, float in_angle, float in_length)
bool operator<(const Segment &s)
Keeps all the supporting information about a specific vanishing point.
std::vector< Segment > supportingSegments
VanishingPoint(Point2D< int > in_vp, float in_likelihood)