Bonjour,

J'ai récupéré un code source pour qt mais impossible de le compiler. Le problème se trouve au niveau d'une classe et de son .h, les voici ci-dessous:

colordetector.h:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
 
#if !defined COLORDETECT
#define COLORDETECT
 
#include <opencv2/opencv.hpp>
 
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
colordetector.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
#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;
}
Quand je compile j'ai l'erreur suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
colordetector.cpp:20: multiple definition of `ColorDetector::process(cv::Mat const&)' first defined here
Ce qui lui pose problème est qu'il n'autorise pas le colordetector.cpp a définir l'implémentation de la fonction process?

Cependant ceci devrait marcher non?