Multiple Definition
Verfasst: 26. Februar 2012 20:32
Hallo zusammen.
Blamieren möchte ich mich wirklich nicht, aber vllt. finde ich hier wieder ein wenig Hilfe. Ich habe folgende header Datei mit einer Klassendefinition 'colordetector.h':
class ColorDetector {
private:
// minimum acceptable distance
int minDist;
// target color
cv::Vec3b target;
// image containing resulting binary map
cv::Mat result;
// image containing color converted image
cv::Mat converted;
// inline private member function
// Computes the distance from target color.
int getDistance(const cv::Vec3b& color) const {
// return static_cast<int>(cv::norm<int,3>(cv::Vec3i(color[0]-target[0],color[1]-target[1],color[2]-target[2])));
return abs(color[0]-target[0])+
abs(color[1]-target[1])+
abs(color[2]-target[2]);
}
public:
// empty constructor
ColorDetector() : minDist(100) {
// default parameter initialization here
target[0]= target[1]= target[2]= 0;
}
// Getters and setters
// Sets the color distance threshold.
// Threshold must be positive, otherwise distance threshold
// is set to 0.
void setColorDistanceThreshold(int distance) {
if (distance<0)
distance=0;
minDist= distance;
}
// Gets the color distance threshold
int getColorDistanceThreshold() const {
return minDist;
}
// Sets the color to be detected
void setTargetColor(unsigned char red, unsigned char green, unsigned char blue) {
cv::Mat tmp(1,1,CV_8UC3);
tmp.at<cv::Vec3b>(0,0)[0]= blue;
tmp.at<cv::Vec3b>(0,0)[1]= green;
tmp.at<cv::Vec3b>(0,0)[2]= red;
// Converting the target to Lab color space
cv::cvtColor(tmp, tmp, CV_BGR2Lab);
target= tmp.at<cv::Vec3b>(0,0);
}
// Sets the color to be detected
void setTargetColor(cv::Vec3b color) {
cv::Mat tmp(1,1,CV_8UC3);
tmp.at<cv::Vec3b>(0,0)= color;
// Converting the target to Lab color space
cv::cvtColor(tmp, tmp, CV_BGR2Lab);
target= tmp.at<cv::Vec3b>(0,0);
}
// Gets the color to be detected
cv::Vec3b getTargetColor() const {
return target;
}
// Processes the image. Returns a 1-channel binary image.
cv::Mat process(const cv::Mat &image);
};
#endif
Den Prozess rufe ich in folgender *.cpp auf 'colordetect.cpp':
#include "colordetector.h"
cv::Mat ColorDetector::process(const cv::Mat &image) {
// re-allocate binary map if necessary
// same size as input image, but 1-channel
result.create(image.rows,image.cols,CV_8U);
// re-allocate intermediate image if necessary
converted.create(image.rows,image.cols,image.type());
// Converting to Lab color space
cv::cvtColor(image, converted, CV_BGR2Lab);
// get the iterators
cv::Mat_<cv::Vec3b>::iterator it= converted.begin<cv::Vec3b>();
cv::Mat_<cv::Vec3b>::iterator itend= converted.end<cv::Vec3b>();
cv::Mat_<uchar>::iterator itout= result.begin<uchar>();
// for each pixel
for ( ; it!= itend; ++it, ++itout) {
// process each pixel ---------------------
// compute distance from target color
if (getDistance(*it)<minDist) {
*itout= 255;
} else {
*itout= 0;
}
// end of pixel processing ----------------
}
return result;
};
Jetzt bekomme ich beim kompilieren zwei Hinweise: 1. Overriding commands for target 'release/colordetector.o'
ignoring old commands for target 'release/colordetector.o'
und die folgende Fehlermeldung:
multiple definition of 'ColorDetector::process(cv::Mat const&)'
Ich habe nun im Internet gefunden, dass es bei Variablen zu mehrfachdeklarationen innerhalb des Headers kommen kann und diese als "extern" eingebunden werden müssen. Ich bin mir nicht sicher, aber mit Klassen funktioniert das doch nicht, oder??
Vielen Dank fürs durchschauen.
Boris
Blamieren möchte ich mich wirklich nicht, aber vllt. finde ich hier wieder ein wenig Hilfe. Ich habe folgende header Datei mit einer Klassendefinition 'colordetector.h':
class ColorDetector {
private:
// minimum acceptable distance
int minDist;
// target color
cv::Vec3b target;
// image containing resulting binary map
cv::Mat result;
// image containing color converted image
cv::Mat converted;
// inline private member function
// Computes the distance from target color.
int getDistance(const cv::Vec3b& color) const {
// return static_cast<int>(cv::norm<int,3>(cv::Vec3i(color[0]-target[0],color[1]-target[1],color[2]-target[2])));
return abs(color[0]-target[0])+
abs(color[1]-target[1])+
abs(color[2]-target[2]);
}
public:
// empty constructor
ColorDetector() : minDist(100) {
// default parameter initialization here
target[0]= target[1]= target[2]= 0;
}
// Getters and setters
// Sets the color distance threshold.
// Threshold must be positive, otherwise distance threshold
// is set to 0.
void setColorDistanceThreshold(int distance) {
if (distance<0)
distance=0;
minDist= distance;
}
// Gets the color distance threshold
int getColorDistanceThreshold() const {
return minDist;
}
// Sets the color to be detected
void setTargetColor(unsigned char red, unsigned char green, unsigned char blue) {
cv::Mat tmp(1,1,CV_8UC3);
tmp.at<cv::Vec3b>(0,0)[0]= blue;
tmp.at<cv::Vec3b>(0,0)[1]= green;
tmp.at<cv::Vec3b>(0,0)[2]= red;
// Converting the target to Lab color space
cv::cvtColor(tmp, tmp, CV_BGR2Lab);
target= tmp.at<cv::Vec3b>(0,0);
}
// Sets the color to be detected
void setTargetColor(cv::Vec3b color) {
cv::Mat tmp(1,1,CV_8UC3);
tmp.at<cv::Vec3b>(0,0)= color;
// Converting the target to Lab color space
cv::cvtColor(tmp, tmp, CV_BGR2Lab);
target= tmp.at<cv::Vec3b>(0,0);
}
// Gets the color to be detected
cv::Vec3b getTargetColor() const {
return target;
}
// Processes the image. Returns a 1-channel binary image.
cv::Mat process(const cv::Mat &image);
};
#endif
Den Prozess rufe ich in folgender *.cpp auf 'colordetect.cpp':
#include "colordetector.h"
cv::Mat ColorDetector::process(const cv::Mat &image) {
// re-allocate binary map if necessary
// same size as input image, but 1-channel
result.create(image.rows,image.cols,CV_8U);
// re-allocate intermediate image if necessary
converted.create(image.rows,image.cols,image.type());
// Converting to Lab color space
cv::cvtColor(image, converted, CV_BGR2Lab);
// get the iterators
cv::Mat_<cv::Vec3b>::iterator it= converted.begin<cv::Vec3b>();
cv::Mat_<cv::Vec3b>::iterator itend= converted.end<cv::Vec3b>();
cv::Mat_<uchar>::iterator itout= result.begin<uchar>();
// for each pixel
for ( ; it!= itend; ++it, ++itout) {
// process each pixel ---------------------
// compute distance from target color
if (getDistance(*it)<minDist) {
*itout= 255;
} else {
*itout= 0;
}
// end of pixel processing ----------------
}
return result;
};
Jetzt bekomme ich beim kompilieren zwei Hinweise: 1. Overriding commands for target 'release/colordetector.o'
ignoring old commands for target 'release/colordetector.o'
und die folgende Fehlermeldung:
multiple definition of 'ColorDetector::process(cv::Mat const&)'
Ich habe nun im Internet gefunden, dass es bei Variablen zu mehrfachdeklarationen innerhalb des Headers kommen kann und diese als "extern" eingebunden werden müssen. Ich bin mir nicht sicher, aber mit Klassen funktioniert das doch nicht, oder??
Vielen Dank fürs durchschauen.
Boris