Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Object serialization #91

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
25b5eba
New PixelObjectList Class. Used to store all pixelobjects in a sequen…
Sep 27, 2016
6b2ce3f
Added haversine formula for calculating GPS coordinates
Oct 24, 2016
030044c
Finished GPS corner function
Oct 26, 2016
94566f0
Possibly finished the GPS coordinate implementation
Oct 27, 2016
c15c80a
Add GPS coordinates to Pixel Objects, uniqueness is observed and anal…
Oct 30, 2016
5725401
Reformatted targetanalysis code to use objectlist rather than pixelob…
Dec 10, 2016
02473c7
Redefined TargetAnalysis code flow
Dec 10, 2016
b0e2c06
Added a compareAndAdd function. For now it uses statistics and a bit …
Dec 10, 2016
2996458
Doesn't need to be a class, because it would be a singleton... Simply…
Dec 12, 2016
0b09a23
Code compiles. Whether it works or not is another question. Next step…
Dec 13, 2016
2d1caa6
Started building uniqueness test for pixel objects
Jan 14, 2017
6a7b80d
Added test images where duplicates are present. Preliminary duplicate…
Feb 21, 2017
dfda04b
Object comparison code works now. Optimizations still need to be comp…
Feb 22, 2017
9cc79aa
Removed unecessary file for testdata specific to targetanalysis. Chan…
Mar 9, 2017
1f504f0
Documented the PixelObjectList Class
Mar 9, 2017
d1ace28
Added final comments and documentation to target_analyzer. Also remov…
Mar 9, 2017
c82d14d
Merge Conflict resolved
Apr 8, 2017
2dbb76e
Beginning integration of GPS analysis. Next step, Unit tests for GPS …
Apr 9, 2017
3a7bbe4
Added ability for contours to be GPS located (based on the centroid).…
Apr 10, 2017
63b6663
Finished GPS integration. Added tests to test functionality.
Apr 12, 2017
9c05359
Colour Comparison Working. The fuzzy logic which groups duplicate obj…
Apr 19, 2017
bc1b157
TargetAnalyzer is the settings singleton. It now contains threshold a…
Apr 19, 2017
3e8bc64
Optimized addition of nodes, fixed issues with private/public members
Apr 22, 2017
33df7f8
compareContour changed to be super efficient. It is an order of magni…
Apr 23, 2017
99271e8
Merged Conflicts
Apr 27, 2017
0fe008e
Fixed to incorporate new constructor for Frame.h
Apr 27, 2017
ec7b6d6
Added object serialization to JSON
May 2, 2017
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
30 changes: 28 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This file is part of WARG's computer-vision

Copyright (c) 2015, Waterloo Aerial Robotics Group (WARG)
Copyright (c) 2015-2017, Waterloo Aerial Robotics Group (WARG)
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -46,6 +46,7 @@
#include <fstream>
#include "frame.h"
#include "target_identifier.h"
#include "target_analyzer.h"
#include "imgimport.h"
#include "importer.h"
#include "decklink_import.h"
Expand Down Expand Up @@ -81,6 +82,7 @@ int processors;
// Processing module classes
Importer importer;
TargetIdentifier identifier;
TargetAnalyzer * analyzer = NULL;
MetadataInput *logReader = new MetadataInput();

double aveFrameTime = 1000;
Expand Down Expand Up @@ -163,9 +165,16 @@ void worker(Frame* f) {
workers++;
assert(!f->get_img().empty());
identifier.process_frame(f);
if (intermediate && f->get_objects().size() > 0) {
int poSize = f->get_objects().size();
if (intermediate && poSize > 0) {
intermediate_buffer.push(f);
}

//Analyze the image after it is identified
analyzer = TargetAnalyzer::getInstance();
for (int i = 0; i < poSize; i++){
analyzer->analyze_pixelobject(f->get_objects()[i]);
}

workers--;
auto end = std::chrono::steady_clock::now();
Expand Down Expand Up @@ -323,6 +332,23 @@ vector<Command> commands = {
}),
Command("frames.source.update_delay", "Updates the delay for the source at the given index", {"index", "delay"}, [=](State &newState, vector<string> args) {
importer.update_delay(stoi(args[0]), stol(args[1]));
}),
Command("objects.serialize", "Serialize objects to file", {"file_name"}, [=](State &newState, vector<string> args) {
std::ofstream ofs (args[0], std::ofstream::out);

ofs << "[" << endl;

vector<Object*> objects = TargetAnalyzer::getInstance()->extract_objects();
for (Object *o : objects) {
ofs << o->serialize().str() << endl;
o->write_images(outputDir);
}
ofs << "]" << endl;
ofs.close();
}),
Command("objects.cluster.species", "Assigns species based on colour", {"num_species"}, [=](State &newState, vector<string> args) {
vector<Object*> objects = TargetAnalyzer::getInstance()->extract_objects();
// TODO: Cluster by colour and num_species
})
};

Expand Down
79 changes: 46 additions & 33 deletions modules/core/include/frame.h
Original file line number Diff line number Diff line change
@@ -1,44 +1,26 @@
/*
This file is part of WARG's computer-vision
Copyright (c) 2015, Waterloo Aerial Robotics Group (WARG)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Usage of this code MUST be explicitly referenced to WARG and this code
cannot be used in any competition against WARG.
4. Neither the name of the WARG nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY WARG ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL WARG BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef FRAME_H_INCLUDED
#define FRAME_H_INCLUDED

/**
* @file frame.h
* @author WARG
*
* @brief Container class for storing photos or frames of video to be
* processed and analyzed
*
* @section LICENSE
*
* Copyright (c) 2015-2017, Waterloo Aerial Robotics Group (WARG)
* All rights reserved.
*
* This software is licensed under a modified version of the BSD 3
* clause license
* that should have been included with this software in a file called
* COPYING.txt
* Otherwise it is available at:
* https://raw.githubusercontent.com/UWARG/computer-vision/master/COPYING.txt
*/

#ifndef FRAME_H_INCLUDED
#define FRAME_H_INCLUDED

#include <opencv2/core/core.hpp>
#include "metadata.h"
#include <vector>
Expand Down Expand Up @@ -99,6 +81,31 @@ class Frame{
void save(std::string dir);

/**
* @brief Getter for the pixel distance
*
* @return The distance covered by each pixel of the image in the X and Y
* directions.
*/
cv::Point2d get_pixel_distance();

/**
* @brief Setter for the pixel distance
*
* @param The distance covered by each pixel of the image in the X and Y
* directions.
*/
void set_pixel_distance(cv::Point2d);

/**
* @brief Setter for the pixel distance
*
* @param The distance covered by each pixel of the image in the X direction.
* @param The distance covered by each pixel of the image in the Y
* direction.
*/
void set_pixel_distance(double x, double y);

/*
* @brief returns a new undistorted image using the given camera
* Intended for testing purposes, Does not modify the Frame.
* @param camera the camera to use for undistortion
Expand Down Expand Up @@ -133,6 +140,12 @@ class Frame{
*/
std::vector<PixelObject *> objects;

/**
* @brief Distance of each pixel covers in the x and y direction with
* componesation for altitude, camera lens, etc.
*/
cv::Point2d pixel_distance;

/*
* @brief Camera used to capture the frame
*/
Expand Down
49 changes: 15 additions & 34 deletions modules/core/include/metadata.h
Original file line number Diff line number Diff line change
@@ -1,44 +1,25 @@
/*
This file is part of WARG's computer-vision

Copyright (c) 2015, Waterloo Aerial Robotics Group (WARG)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Usage of this code MUST be explicitly referenced to WARG and this code
cannot be used in any competition against WARG.
4. Neither the name of the WARG nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY WARG ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL WARG BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef METADATA_H_INCLUDED
#define METADATA_H_INCLUDED

/**
* @file metadata.h
* @author WARG
*
* @brief Structure for storing plane status information from the time
* that an image was taken
*
* @section LICENSE
*
* Copyright (c) 2015-2017, Waterloo Aerial Robotics Group (WARG)
* All rights reserved.
*
* This software is licensed under a modified version of the BSD 3
* clause license
* that should have been included with this software in a file called
* COPYING.txt
* Otherwise it is available at:
* https://raw.githubusercontent.com/UWARG/computer-vision/master/COPYING.txt
*/

#ifndef METADATA_H_INCLUDED
#define METADATA_H_INCLUDED

struct Metadata{
/**
Expand Down
65 changes: 44 additions & 21 deletions modules/core/include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,41 @@
* @file object.h
* @author WARG
*
*
* @section LICENSE
*
* Copyright (c) 2015, Waterloo Aerial Robotics Group (WARG)
* Copyright (c) 2015-2017, Waterloo Aerial Robotics Group (WARG)
* All rights reserved.
*
* This software is licensed under a modified version of the BSD 3 clause license
* that should have been included with this software in a file called COPYING.txt
* This software is licensed under a modified version of the BSD 3
* clause license
* that should have been included with this software in a file called
* COPYING.txt
* Otherwise it is available at:
* https://raw.githubusercontent.com/UWARG/computer-vision/master/COPYING.txt
*/



#ifndef OBJECT_H_INCLUDED
#define OBJECT_H_INCLUDED

/**
* @class Object
*
* @brief Container class for storing information about
* identified targets in real-world measurements
* Adding PixelObjects consolidates their information
* into the Object
*
*/

#include <opencv2/core/core.hpp>
#include <vector>

class PixelObject;

/*
* @class PixelObject
* @brief Container class for storing information about
* identified targets in real-world measurements
* Adding PixelObjects consolidates their information
* into the Object
*/

class Object {
public:
Object(std::string type);
Object();

/**
* @brief Getter for Object image
Expand All @@ -55,7 +57,7 @@ class Object {
*
* @return GPS co-ordinates of the Object
*/
cv::Point2f get_centroid();
cv::Point2d get_centroid();

/**
* @brief Getter for area
Expand Down Expand Up @@ -83,7 +85,7 @@ class Object {
*
* @return 2D error magnitude of the Object's location in metres
*/
cv::Point2f get_error();
cv::Point2d get_error();

/**
* @brief Getter for error angle
Expand All @@ -96,18 +98,23 @@ class Object {
* @brief Adds given PixelObject to Object's storage
* and recalculate target information
*
* @param o PixelObject to be added
* @param po PixelObject to be added
*/
void add_object(Object * o);
void add_pobject(PixelObject * po);

/**
* @brief Getter for pixel Objects
*
* @return Array containing all of the PixelObjects that were used to
* create this instance of Object
*/
const std::vector<Object *> & get_objects();
const std::vector<PixelObject *> & get_pobjects();

std::stringstream serialize();

void write_images(std::string dir);
private:
int id;

/**
* @brief Cropped Image of the Object
Expand All @@ -127,7 +134,7 @@ class Object {
/**
* @brief GPS co-ordinates of the centre of the Object
*/
cv::Point2f centroid;
cv::Point2d centroid;

/**
* @brief area of the target in square metres
Expand All @@ -147,7 +154,7 @@ class Object {
/**
* @brief Calculated location error of the target as a 2D rectangle in metres
*/
cv::Point2f error;
cv::Point2d error;

/**
* @brief Angle of the error as degrees clockwise from North
Expand All @@ -159,6 +166,22 @@ class Object {
* Each PixelObject is a specific instance of this Object
*/
std::vector<PixelObject *> pixelObjects;

/**
* @brief Updates Object parameters based on the PixelObjects contained
* within it. For now this includes calculating the average
* positions/colours/areas with potential error
*
*/
void update();

/**
* @brief Recalculates Object parameters based on the PixelObjects contained
* within it. For now this includes calculating the average
* positions/colours/areas with potential error
*
*/
void recalculate();
};


Expand Down
Loading