This repository has been archived by the owner on May 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Histogram targetid #53
Open
ZheyuanZhang
wants to merge
11
commits into
UWARG:master
Choose a base branch
from
ZheyuanZhang:histogram
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
db7b40e
update histogram branch
ZheyuanZhang e51b663
histogram part working. The result image is not desirable and the pro…
ZheyuanZhang 7e6c7c4
Histogram codes modified. Codes moved into a subclass of filter. Remo…
ZheyuanZhang 5a6e50f
The filter function no longer returns NULL pointer
ZheyuanZhang 944df73
modified the algorithm. program is now working perfectly with some pi…
ZheyuanZhang 8f8beff
Histogram part finished. Test fails however.
ZheyuanZhang c4d52bc
hist test working but not passing
ZheyuanZhang 7454841
removed unnecessary codes and stylized class names
ZheyuanZhang 6de0cdf
garbage removed
ZheyuanZhang 199e9ed
Histogram test change made. The test is still failing on img_1899.
ZheyuanZhang ff4d05e
Removed GUI codes. Hist test now printing the name of tested image.
ZheyuanZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
include_directories(include ../core/include) | ||
include_directories(include ../core/include ../imgimport/include) | ||
ADD_DEFINITIONS("-DBOOST_LOG_DYN_LINK") | ||
add_library(TargetIdentification src/target_identifier.cpp src/object_detector.cpp src/canny_contour_creator.cpp src/k_means_filter.cpp src/filter.cpp src/qr_identifier.cpp src/contour_comparison.cpp) | ||
target_link_libraries(TargetIdentification ${OpenCV_LIBS} ${Boost_LIBRARIES} ${ZBAR_LIBRARIES} zbar Core) | ||
message("ZBAR: " + ${ZBAR_LIBRARIES}) | ||
add_library(TargetIdentification src/target_identifier.cpp src/object_detector.cpp src/canny_contour_creator.cpp src/k_means_filter.cpp src/filter.cpp src/qr_identifier.cpp src/histogram.cpp src/contour_comparison.cpp) | ||
target_link_libraries(TargetIdentification ${OpenCV_LIBS} ${Boost_LIBRARIES} ${ZBAR_LIBRARIES} zbar Core ImageImport) | ||
target_compile_features(TargetIdentification PRIVATE cxx_range_for) | ||
add_subdirectory("test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
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 HISTOGRAM_H_INCLUDED | ||
#define HISTOGRAM_H_INCLUDED | ||
#include "opencv2/highgui/highgui.hpp" | ||
#include "opencv2/imgcodecs.hpp" | ||
#include "opencv2/imgproc/imgproc.hpp" | ||
#include "frame.h" | ||
#include "pictureimport.h" | ||
#include <iostream> | ||
#include <stdio.h> | ||
#include <vector> | ||
#include "filter.h" | ||
#include <cmath> | ||
|
||
class target_range{ | ||
public: | ||
void input_hue(int a); | ||
bool belong(cv::Vec3b c); | ||
private: | ||
std::vector<int> hue; | ||
}; | ||
|
||
class hist_filter : public Filter{ | ||
public: | ||
hist_filter(); | ||
~hist_filter(); | ||
cv::Mat * filter(const cv::Mat & src); | ||
private: | ||
int count=0; | ||
double avg_hue[18],hue_multi[18]; | ||
// double avg_sat[16],sat_multi[16]; | ||
int avg_brightness=0; | ||
}; | ||
#endif // HISTOGRAM_H_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include "histogram.h" | ||
using namespace std; | ||
using namespace cv; | ||
|
||
void target_range::input_hue(int a){ | ||
hue.push_back(a); | ||
} | ||
|
||
bool target_range::belong(Vec3b c){ | ||
for(int i=0;i<hue.size();i++){ | ||
if(hue.at(i)==c.val[0]){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
hist_filter::hist_filter() | ||
:Filter(){ | ||
} | ||
|
||
hist_filter::~hist_filter(){ | ||
} | ||
|
||
Mat* hist_filter::filter(const Mat & src){ | ||
Mat bgr_img=src.clone(); | ||
int brightness; | ||
for(int y=0;y<bgr_img.rows;y++){ | ||
for(int x=0;x<bgr_img.cols;x++){ | ||
Vec3b colour = bgr_img.at<Vec3b>(Point(x, y)); | ||
brightness+=colour.val[0]; | ||
brightness+=colour.val[1]; | ||
brightness+=colour.val[2]; | ||
} | ||
} | ||
brightness/=(bgr_img.rows*bgr_img.cols*3); | ||
avg_brightness=(avg_brightness*count+brightness)/(count+1); | ||
for(int y=0;y<bgr_img.rows;y++){ | ||
for(int x=0;x<bgr_img.cols;x++){ | ||
bgr_img.at<Vec3b>(Point(x, y)).val[0]=bgr_img.at<Vec3b>(Point(x, y)).val[0]+avg_brightness-brightness; | ||
if(bgr_img.at<Vec3b>(Point(x, y)).val[0]>255) bgr_img.at<Vec3b>(Point(x, y)).val[0]=255; | ||
if(bgr_img.at<Vec3b>(Point(x, y)).val[0]<0) bgr_img.at<Vec3b>(Point(x, y)).val[0]=0; | ||
bgr_img.at<Vec3b>(Point(x, y)).val[1]=bgr_img.at<Vec3b>(Point(x, y)).val[1]+avg_brightness-brightness; | ||
if(bgr_img.at<Vec3b>(Point(x, y)).val[1]>255) bgr_img.at<Vec3b>(Point(x, y)).val[1]=255; | ||
if(bgr_img.at<Vec3b>(Point(x, y)).val[1]<0) bgr_img.at<Vec3b>(Point(x, y)).val[1]=0; | ||
bgr_img.at<Vec3b>(Point(x, y)).val[2]=bgr_img.at<Vec3b>(Point(x, y)).val[2]+avg_brightness-brightness; | ||
if(bgr_img.at<Vec3b>(Point(x, y)).val[2]>255) bgr_img.at<Vec3b>(Point(x, y)).val[2]=255; | ||
if(bgr_img.at<Vec3b>(Point(x, y)).val[2]<0) bgr_img.at<Vec3b>(Point(x, y)).val[2]=0; | ||
} | ||
} | ||
Mat* hsv_img=new Mat; | ||
cvtColor(bgr_img,*hsv_img,CV_BGR2HSV); | ||
blur(*hsv_img,*hsv_img,Size(3,3)); | ||
int hueSize = 18; | ||
int satSize=16; | ||
vector<Mat> bgr_planes; | ||
split(*hsv_img,bgr_planes); | ||
float hue_range[]={0,180}; | ||
const float* hueRange={hue_range}; | ||
// float sat_range[]={0,256}; | ||
// const float* satRange={sat_range}; | ||
bool uniform = true; bool accumulate = false; | ||
Mat hue_hist; | ||
// Mat sat_hist; | ||
calcHist( &bgr_planes[0], 1, 0, Mat(), hue_hist, 1, &hueSize, &hueRange, uniform, accumulate ); | ||
// calcHist( &bgr_planes[1], 1, 0, Mat(), sat_hist, 1, &satSize, &satRange, uniform, accumulate ); | ||
for( int i = 0; i < hueSize; i++ ){ | ||
avg_hue[i]=(avg_hue[i]*count+cvRound(hue_hist.at<float>(i)))/(count+1); | ||
} | ||
/* for( int i = 0; i < satSize; i++ ){ | ||
avg_sat[i]=(avg_sat[i]*count+cvRound(sat_hist.at<float>(i)))/(count+1); | ||
}*/ | ||
count++; | ||
int tmp; | ||
for( int i = 0; i < hueSize; i++ ){ | ||
tmp=cvRound(hue_hist.at<float>(i)-avg_hue[i]); | ||
if(tmp<0) tmp=0; | ||
hue_multi[i]=pow(tmp/hue_hist.at<float>(i),2); | ||
} | ||
/* for( int i = 0; i < satSize; i++ ){ | ||
tmp=cvRound(sat_hist.at<float>(i)-avg_sat[i]); | ||
if(tmp<0) tmp=0; | ||
sat_multi[i]=pow(tmp/sat_hist.at<float>(i),3); | ||
}*/ | ||
Mat* result=new Mat; | ||
cvtColor(*hsv_img,*result,CV_HSV2BGR); | ||
for(int y=0;y<hsv_img->rows;y++){ | ||
for(int x=0;x<hsv_img->cols;x++){ | ||
Vec3b colour = hsv_img->at<Vec3b>(Point(x, y)); | ||
result->at<Vec3b>(Point(x, y)).val[0]=result->at<Vec3b>(Point(x, y)).val[0]*hue_multi[colour.val[0]/10]*colour.val[1]/256; | ||
result->at<Vec3b>(Point(x, y)).val[1]=result->at<Vec3b>(Point(x, y)).val[1]*hue_multi[colour.val[0]/10]*colour.val[1]/256; | ||
result->at<Vec3b>(Point(x, y)).val[2]=result->at<Vec3b>(Point(x, y)).val[2]*hue_multi[colour.val[0]/10]*colour.val[1]/256; | ||
} | ||
} | ||
return result; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#define BOOST_TEST_DYN_LINK | ||
#define BOOST_TEST_MODULE TargetIdentification | ||
#include "histogram.h" | ||
#include <boost/test/unit_test.hpp> | ||
#include <boost/log/trivial.hpp> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <opencv2/core/core.hpp> | ||
#include <opencv2/highgui/highgui.hpp> | ||
#include "target_identifier.h" | ||
#include "canny_contour_creator.h" | ||
#include "k_means_filter.h" | ||
#include "frame.h" | ||
#include "benchmark.h" | ||
#include "contour_comparison.h" | ||
using namespace std; | ||
using namespace cv; | ||
using namespace boost; | ||
|
||
BOOST_AUTO_TEST_CASE(hist_test){ | ||
vector<int> n; | ||
n.push_back(3); | ||
string telemetry_path=boost::unit_test::framework::master_test_suite().argv[2]; | ||
string filePath=boost::unit_test::framework::master_test_suite().argv[1]; | ||
ofstream fout(telemetry_path); | ||
fout<<"time,timeError,lat,lon,latError,lonError,pitch,roll,pitchRate,rollRate,yawRate,altitude,heading,altError,headingError,photonum"<<endl; | ||
for(int i=0;i<25;i++) | ||
{ | ||
for(int j=0;j<15;j++){ | ||
fout<<j<<","; | ||
} | ||
fout<<i<<endl; | ||
} | ||
hist_filter test_filter; | ||
PictureImport* input=new PictureImport(telemetry_path,filePath,n); | ||
Frame* src; | ||
for(src=input->next_frame();src!=NULL;src=input->next_frame()){ | ||
const Mat buffer=src->get_img(); | ||
test_filter.filter(buffer); | ||
} | ||
delete input; | ||
PictureImport* in=new PictureImport(telemetry_path,filePath,n); | ||
Mat* show; | ||
for(src=in->next_frame();src!=NULL;src=in->next_frame()){ | ||
const Mat buffer=src->get_img(); | ||
show=test_filter.filter(buffer); | ||
KMeansFilter filter; | ||
CannyContourCreator ccreator; | ||
Mat * filtered = filter.filter(buffer); | ||
vector<vector<Point> > * results = ccreator.get_contours(*filtered); | ||
vector<vector<Point> > * expected = ccreator.get_contours(*show); | ||
double diff = compare_contours(*results, *expected); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not terribly useful to be comparing the results to the k_means filter results since they are largely unknown. You want to be comparing them to a contour that we know to be more or less correct, i.e. one determined manually. I also think that we should allow the threshold for the contour creator to be set by its constructor (or set up a way of doing on the fly adjustments such as what I added to the filter class). From the results I was seeing on Thursday this filter will probably benefit from a lower threshold than the kmeans segmentation filter. |
||
BOOST_CHECK(diff > 0.01); | ||
BOOST_TEST_MESSAGE("RESULT: " << diff); | ||
/* namedWindow("original",WINDOW_NORMAL); | ||
resizeWindow("original", 900, 900); | ||
imshow("original",buffer); | ||
namedWindow("display",WINDOW_NORMAL); | ||
resizeWindow("display", 900, 900); | ||
imshow("display",*show); | ||
waitKey(0);*/ | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
time,timeError,lat,lon,latError,lonError,pitch,roll,pitchRate,rollRate,yawRate,altitude,heading,altError,headingError,photonum | ||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0 | ||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of things I don't like about outputting this csv.
First of all It's not actually necessary for a test that's got nothing to do with the metadata.
But also you're putting it in a fixed-path source directory (and then of course the generated file gets included in the commit), if anything it should go with the generated build files. I would point out however that we do have the actual telemetry logs for the photos in the testdata directory. It would make more sense to include them and use them instead of generating placeholder files.