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 4 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) | ||
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) | ||
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,65 @@ | ||
/* | ||
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" | ||
|
||
class target_range{ | ||
public: | ||
void input_b(int a); | ||
void input_g(int a); | ||
void input_r(int a); | ||
bool belong(cv::Vec3b c); | ||
private: | ||
std::vector<int> blue; | ||
std::vector<int> green; | ||
std::vector<int> red; | ||
}; | ||
|
||
class hist_filter : public Filter{ | ||
public: | ||
hist_filter(); | ||
~hist_filter(); | ||
cv::Mat * filter(const cv::Mat & src); | ||
private: | ||
int count=0; | ||
double avg_b[256],avg_g[256],avg_r[256]; | ||
}; | ||
#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,95 @@ | ||
#include "histogram.h" | ||
using namespace std; | ||
using namespace cv; | ||
|
||
void target_range::input_b(int a){ | ||
blue.push_back(a); | ||
} | ||
|
||
void target_range::input_g(int a){ | ||
green.push_back(a); | ||
} | ||
|
||
void target_range::input_r(int a){ | ||
red.push_back(a); | ||
} | ||
|
||
bool target_range::belong(Vec3b c){ | ||
for(int i=0;i<blue.size();i++){ | ||
if(blue.at(i)==c.val[0]){ | ||
for(int j=0;j<green.size();j++){ | ||
if(green.at(j)==c.val[1]){ | ||
for(int k=0;k<red.size();k++){ | ||
if(red.at(k)==c.val[2]) | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
hist_filter::hist_filter() | ||
:Filter(){ | ||
} | ||
|
||
hist_filter::~hist_filter(){ | ||
} | ||
|
||
Mat* hist_filter::filter(const Mat & src){ | ||
int histSize = 256; | ||
vector<Mat> bgr_planes; | ||
split(src,bgr_planes); | ||
float range[] = { 0, 256 } ; | ||
const float* histRange = { range }; | ||
bool uniform = true; bool accumulate = false; | ||
Mat* b_hist=new Mat; | ||
Mat* g_hist=new Mat; | ||
Mat* r_hist=new Mat; | ||
calcHist( &bgr_planes[0], 1, 0, Mat(), *b_hist, 1, &histSize, &histRange, uniform, accumulate ); | ||
calcHist( &bgr_planes[1], 1, 0, Mat(), *g_hist, 1, &histSize, &histRange, uniform, accumulate ); | ||
calcHist( &bgr_planes[2], 1, 0, Mat(), *r_hist, 1, &histSize, &histRange, uniform, accumulate ); | ||
int hist_w = 512; int hist_h = 400; | ||
int bin_w = cvRound( (double) hist_w/histSize ); | ||
Mat histImage( hist_h, hist_w, CV_8UC3, Scalar( 0,0,0) ); | ||
normalize(*b_hist, *b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() ); | ||
normalize(*g_hist, *g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() ); | ||
normalize(*r_hist, *r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() ); | ||
for( int i = 0; i < histSize; i++ ){ | ||
avg_b[i]=(avg_b[i]*count+cvRound(b_hist->at<float>(i)))/(count+1); | ||
avg_g[i]=(avg_g[i]*count+cvRound(g_hist->at<float>(i)))/(count+1); | ||
avg_r[i]=(avg_r[i]*count+cvRound(r_hist->at<float>(i)))/(count+1); | ||
} | ||
count++; | ||
int tmp; | ||
int minimal=300; | ||
target_range* pack=new target_range; | ||
for( int i = 0; i < histSize; i++ ){ | ||
tmp=cvRound(b_hist->at<float>(i)-avg_b[i]); | ||
if(tmp>minimal){ | ||
pack->input_b(i); | ||
} | ||
tmp=cvRound(g_hist->at<float>(i)-avg_g[i]); | ||
if(tmp>minimal){ | ||
pack->input_g(i); | ||
} | ||
tmp=cvRound(r_hist->at<float>(i)-avg_r[i]); | ||
if(tmp>minimal){ | ||
pack->input_r(i); | ||
} | ||
} | ||
Mat* result=new Mat(src); | ||
for(int y=0;y<result->rows;y++){ | ||
for(int x=0;x<result->cols;x++){ | ||
Vec3b colour = result->at<Vec3b>(Point(x, y)); | ||
if(!pack->belong(colour)){ | ||
result->at<Vec3b>(Point(x, y)).val[0]=0; | ||
result->at<Vec3b>(Point(x, y)).val[1]=0; | ||
result->at<Vec3b>(Point(x, y)).val[2]=0; | ||
} | ||
} | ||
} | ||
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,46 @@ | ||
#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> | ||
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); | ||
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. There are a couple of things I don't like about outputting this csv. |
||
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; | ||
} | ||
PictureImport* input=new PictureImport(telemetry_path,filePath,n); | ||
hist_filter test_filter; | ||
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); | ||
namedWindow("display",WINDOW_NORMAL); | ||
resizeWindow("display", 1000, 1000); | ||
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.
This doesn't copy the image. You want the Mat::clone function. The Mat object itself is just a container around an internal data structure and the copy constructor just makes a shallow copy in this case, meaning that you're modifying the original image.