Praktikum Bildbearbeitung

Zum Betrachten der nächsten Seite "Bild ab" drücken oder nach unten scrollen.

for_each_pixel mit Funktor


void for_each_pixel(cv::Mat & m, std::function<void(cv::Mat &, int, int)> f) {
  for (int y = 0; y < m.rows; y++) {
    for (int x = 0; x < m.cols; x++) {
      f(m, y, x);
    }
  }
}
      
Erstes Ziel der Optimierung sollte immer der Algorithmus sein.

Fallunterscheidung aus Schleife ziehen


for_each_pixel(img, [](cv::Mat & m, int y, int x) {
  
  if (bba::isColor(m)) {
    m.at<cv::Vec3b>(y,x) += cv::Vec3b(1,1,1);
  } else {
    m.at<unsigned char>(y,x) += 1;
  }
  
});
      

if (bba::isColor(m)) {
  
  for_each_pixel(img, [](cv::Mat & m, int y, int x) {
    m.at<cv::Vec3b>(y,x) += cv::Vec3b(1,1,1);
  });
  
} else {
  
  for_each_pixel(img, [](cv::Mat & m, int y, int x) {
    m.at<unsigned char>(y,x) += 1;
  });
  
}
      

for_each_pixel als Vorlage

Der Aufruf von f wird meistens nicht durch inlining eliminiert, da f in der Regel zur Übersetzungszeit nicht feststeht.


void for_each_pixel(cv::Mat & m, std::function<void(cv::Mat &, int, int)> f) {
  for (int y = 0; y < m.rows; y++) {
    for (int x = 0; x < m.cols; x++) {
      f(m, y, x);
    }
  }
}
      

Eine Lösung: Nicht f einbetten, sondern die Schleifen mit Vorlagen darum herum bauen.


template <typename F> void for_each_pixel(cv::Mat & m, F f) {
  for (int y = 0; y < m.rows; y++) {
    for (int x = 0; x < m.cols; x++) {
      f(m, y, x);
    }
  }
}
      

Der Code


// Vorlage
template <typename F> void for_each_pixel(cv::Mat & m, F f) {
  for (int y = 0; y < m.rows; y++) {
    for (int x = 0; x < m.cols; x++) {
      f(m, y, x);
    }
  }
}
// konkreter Aufruf
for_each_pixel(img, [](cv::Mat & m, int y, int x) {
  m.at<unsigned char>(y,x) = m.at<unsigned char>(y,x);
});
      

kann vom Compiler transparent zusammengesetzt werden zu


for (int y = 0; y < m.rows; y++) {
  for (int x = 0; x < m.cols; x++) {
    m.at<unsigned char>(y,x) = m.at<unsigned char>(y,x);
  }
}
      

. Der Unterprogrammsprung ist erfolgreich vermieden worden.

Experten können sich ein vereinfachtes Beispiel hier ansehen.

Nachteil von Vorlagen

Bei Fehlern sind die meldungen des Compilers etwas unübersichtlich. Hier wurde versehentlich ein cv::Vec3b anstelle eines unsigned int verwendet.

template.cpp: In lambda function:
template.cpp:15:30: error: no match for ‘operator+=’ (operand types are ‘unsigned char’ and ‘cv::Vec3b’ {aka ‘cv::Vec<unsigned char, 3>’})
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
In file included from opencv2/core.hpp:57,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/matx.hpp:1185:19: note: candidate: ‘template<class _Tp1, class _Tp2, int m, int n> cv::Matx<_Tp, m, n>& cv::operator+=(cv::Matx<_Tp, m, n>&, const cv::Matx<_Tp2, m, n>&)’
 1185 | Matx<_Tp1, m, n>& operator += (Matx<_Tp1, m, n>& a, const Matx<_Tp2, m, n>& b)
      |                   ^~~~~~~~
opencv2/core/matx.hpp:1185:19: note:   template argument deduction/substitution failed:
template.cpp:15:48: note:   mismatched types ‘cv::Matx<_Tp, m, n>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:57,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/matx.hpp:1313:16: note: candidate: ‘template<class _Tp1, class _Tp2, int cn> cv::Vec<_Tp, n>& cv::operator+=(cv::Vec<_Tp, n>&, const cv::Vec<_Tp2, cn>&)’
 1313 | Vec<_Tp1, cn>& operator += (Vec<_Tp1, cn>& a, const Vec<_Tp2, cn>& b)
      |                ^~~~~~~~
opencv2/core/matx.hpp:1313:16: note:   template argument deduction/substitution failed:
template.cpp:15:48: note:   mismatched types ‘cv::Vec<_Tp, n>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:58,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/types.hpp:1031:15: note: candidate: ‘template<class _Tp> cv::Complex<_Tp>& cv::operator+=(cv::Complex<_Tp>&, const cv::Complex<_Tp>&)’
 1031 | Complex<_Tp>& operator += (Complex<_Tp>& a, const Complex<_Tp>& b)
      |               ^~~~~~~~
opencv2/core/types.hpp:1031:15: note:   template argument deduction/substitution failed:
template.cpp:15:48: note:   mismatched types ‘cv::Complex<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:58,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/types.hpp:1097:15: note: candidate: ‘template<class _Tp> cv::Complex<_Tp>& cv::operator+=(cv::Complex<_Tp>&, _Tp)’
 1097 | Complex<_Tp>& operator += (Complex<_Tp>& a, _Tp b)
      |               ^~~~~~~~
opencv2/core/types.hpp:1097:15: note:   template argument deduction/substitution failed:
template.cpp:15:48: note:   mismatched types ‘cv::Complex<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:58,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/types.hpp:1235:14: note: candidate: ‘template<class _Tp> cv::Point_<_Tp>& cv::operator+=(cv::Point_<_Tp>&, const cv::Point_<_Tp>&)’
 1235 | Point_<_Tp>& operator += (Point_<_Tp>& a, const Point_<_Tp>& b)
      |              ^~~~~~~~
opencv2/core/types.hpp:1235:14: note:   template argument deduction/substitution failed:
template.cpp:15:48: note:   mismatched types ‘cv::Point_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:58,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/types.hpp:1496:15: note: candidate: ‘template<class _Tp> cv::Point3_<_Tp>& cv::operator+=(cv::Point3_<_Tp>&, const cv::Point3_<_Tp>&)’
 1496 | Point3_<_Tp>& operator += (Point3_<_Tp>& a, const Point3_<_Tp>& b)
      |               ^~~~~~~~
opencv2/core/types.hpp:1496:15: note:   template argument deduction/substitution failed:
template.cpp:15:48: note:   mismatched types ‘cv::Point3_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:58,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/types.hpp:1775:13: note: candidate: ‘template<class _Tp> cv::Size_<_Tp>& cv::operator+=(cv::Size_<_Tp>&, const cv::Size_<_Tp>&)’
 1775 | Size_<_Tp>& operator += (Size_<_Tp>& a, const Size_<_Tp>& b)
      |             ^~~~~~~~
opencv2/core/types.hpp:1775:13: note:   template argument deduction/substitution failed:
template.cpp:15:48: note:   mismatched types ‘cv::Size_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:58,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/types.hpp:1918:13: note: candidate: ‘template<class _Tp> cv::Rect_<_Tp>& cv::operator+=(cv::Rect_<_Tp>&, const cv::Point_<_Tp>&)’
 1918 | Rect_<_Tp>& operator += ( Rect_<_Tp>& a, const Point_<_Tp>& b )
      |             ^~~~~~~~
opencv2/core/types.hpp:1918:13: note:   template argument deduction/substitution failed:
template.cpp:15:48: note:   mismatched types ‘cv::Rect_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:58,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/types.hpp:1934:13: note: candidate: ‘template<class _Tp> cv::Rect_<_Tp>& cv::operator+=(cv::Rect_<_Tp>&, const cv::Size_<_Tp>&)’
 1934 | Rect_<_Tp>& operator += ( Rect_<_Tp>& a, const Size_<_Tp>& b )
      |             ^~~~~~~~
opencv2/core/types.hpp:1934:13: note:   template argument deduction/substitution failed:
template.cpp:15:48: note:   mismatched types ‘cv::Rect_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:58,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/types.hpp:2256:15: note: candidate: ‘template<class _Tp> cv::Scalar_<_Tp>& cv::operator+=(cv::Scalar_<_Tp>&, const cv::Scalar_<_Tp>&)’
 2256 | Scalar_<_Tp>& operator += (Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
      |               ^~~~~~~~
opencv2/core/types.hpp:2256:15: note:   template argument deduction/substitution failed:
template.cpp:15:48: note:   mismatched types ‘cv::Scalar_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core/mat.hpp:3724,
                 from opencv2/core.hpp:59,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/mat.inl.hpp:3483:6: note: candidate: ‘cv::Mat& cv::operator+=(cv::Mat&, const cv::MatExpr&)’
 3483 | Mat& operator += (Mat& a, const MatExpr& b)
      |      ^~~~~~~~
opencv2/core/mat.inl.hpp:3483:24: note:   no known conversion for argument 1 from ‘unsigned char’ to ‘cv::Mat&’
 3483 | Mat& operator += (Mat& a, const MatExpr& b)
      |                   ~~~~~^
opencv2/core/mat.inl.hpp:3490:12: note: candidate: ‘const cv::Mat& cv::operator+=(const cv::Mat&, const cv::MatExpr&)’
 3490 | const Mat& operator += (const Mat& a, const MatExpr& b)
      |            ^~~~~~~~
opencv2/core/mat.inl.hpp:3490:36: note:   no known conversion for argument 1 from ‘unsigned char’ to ‘const cv::Mat&’
 3490 | const Mat& operator += (const Mat& a, const MatExpr& b)
      |                         ~~~~~~~~~~~^
opencv2/core/mat.inl.hpp:3497:12: note: candidate: ‘template<class _Tp> cv::Mat_<_Tp>& cv::operator+=(cv::Mat_<_Tp>&, const cv::MatExpr&)’
 3497 | Mat_<_Tp>& operator += (Mat_<_Tp>& a, const MatExpr& b)
      |            ^~~~~~~~
opencv2/core/mat.inl.hpp:3497:12: note:   template argument deduction/substitution failed:
template.cpp:15:48: note:   mismatched types ‘cv::Mat_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core/mat.hpp:3724,
                 from opencv2/core.hpp:59,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/mat.inl.hpp:3504:18: note: candidate: ‘template<class _Tp> const cv::Mat_<_Tp>& cv::operator+=(const cv::Mat_<_Tp>&, const cv::MatExpr&)’
 3504 | const Mat_<_Tp>& operator += (const Mat_<_Tp>& a, const MatExpr& b)
      |                  ^~~~~~~~
opencv2/core/mat.inl.hpp:3504:18: note:   template argument deduction/substitution failed:
template.cpp:15:48: note:   mismatched types ‘const cv::Mat_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:3291,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/operations.hpp:255:22: note: candidate: ‘cv::Mat& cv::operator+=(cv::Mat&, const cv::Mat&)’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:258:5: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  258 |     CV_MAT_AUG_OPERATOR1(op, cvop, A, B)      \
      |     ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:269:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR’
  269 | CV_MAT_AUG_OPERATOR  (+=, cv::add(a,b,a), Mat, Mat)
      | ^~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:38: note:   no known conversion for argument 1 from ‘unsigned char’ to ‘cv::Mat&’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                                      ^
opencv2/core/operations.hpp:258:5: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  258 |     CV_MAT_AUG_OPERATOR1(op, cvop, A, B)      \
      |     ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:269:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR’
  269 | CV_MAT_AUG_OPERATOR  (+=, cv::add(a,b,a), Mat, Mat)
      | ^~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:22: note: candidate: ‘const cv::Mat& cv::operator+=(const cv::Mat&, const cv::Mat&)’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:259:5: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  259 |     CV_MAT_AUG_OPERATOR1(op, cvop, const A, B)
      |     ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:269:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR’
  269 | CV_MAT_AUG_OPERATOR  (+=, cv::add(a,b,a), Mat, Mat)
      | ^~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:38: note:   no known conversion for argument 1 from ‘unsigned char’ to ‘const cv::Mat&’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                                      ^
opencv2/core/operations.hpp:259:5: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  259 |     CV_MAT_AUG_OPERATOR1(op, cvop, const A, B)
      |     ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:269:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR’
  269 | CV_MAT_AUG_OPERATOR  (+=, cv::add(a,b,a), Mat, Mat)
      | ^~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:22: note: candidate: ‘cv::Mat& cv::operator+=(cv::Mat&, const Scalar&)’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:258:5: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  258 |     CV_MAT_AUG_OPERATOR1(op, cvop, A, B)      \
      |     ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:270:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR’
  270 | CV_MAT_AUG_OPERATOR  (+=, cv::add(a,b,a), Mat, Scalar)
      | ^~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:38: note:   no known conversion for argument 1 from ‘unsigned char’ to ‘cv::Mat&’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                                      ^
opencv2/core/operations.hpp:258:5: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  258 |     CV_MAT_AUG_OPERATOR1(op, cvop, A, B)      \
      |     ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:270:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR’
  270 | CV_MAT_AUG_OPERATOR  (+=, cv::add(a,b,a), Mat, Scalar)
      | ^~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:22: note: candidate: ‘const cv::Mat& cv::operator+=(const cv::Mat&, const Scalar&)’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:259:5: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  259 |     CV_MAT_AUG_OPERATOR1(op, cvop, const A, B)
      |     ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:270:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR’
  270 | CV_MAT_AUG_OPERATOR  (+=, cv::add(a,b,a), Mat, Scalar)
      | ^~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:38: note:   no known conversion for argument 1 from ‘unsigned char’ to ‘const cv::Mat&’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                                      ^
opencv2/core/operations.hpp:259:5: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  259 |     CV_MAT_AUG_OPERATOR1(op, cvop, const A, B)
      |     ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:270:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR’
  270 | CV_MAT_AUG_OPERATOR  (+=, cv::add(a,b,a), Mat, Scalar)
      | ^~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:22: note: candidate: ‘template<class _Tp> cv::Mat_<_Tp>& cv::operator+=(cv::Mat_<_Tp>&, const cv::Mat&)’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:262:28: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  262 |     template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \
      |                            ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:271:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_T’
  271 | CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat)
      | ^~~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:22: note:   template argument deduction/substitution failed:
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:262:28: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  262 |     template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \
      |                            ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:271:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_T’
  271 | CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat)
      | ^~~~~~~~~~~~~~~~~~~~~
template.cpp:15:48: note:   mismatched types ‘cv::Mat_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:3291,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/operations.hpp:255:22: note: candidate: ‘template<class _Tp> const cv::Mat_<_Tp>& cv::operator+=(const cv::Mat_<_Tp>&, const cv::Mat&)’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:263:28: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  263 |     template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, const A, B)
      |                            ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:271:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_T’
  271 | CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat)
      | ^~~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:22: note:   template argument deduction/substitution failed:
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:263:28: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  263 |     template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, const A, B)
      |                            ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:271:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_T’
  271 | CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat)
      | ^~~~~~~~~~~~~~~~~~~~~
template.cpp:15:48: note:   mismatched types ‘const cv::Mat_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:3291,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/operations.hpp:255:22: note: candidate: ‘template<class _Tp> cv::Mat_<_Tp>& cv::operator+=(cv::Mat_<_Tp>&, const Scalar&)’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:262:28: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  262 |     template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \
      |                            ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:272:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_T’
  272 | CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Scalar)
      | ^~~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:22: note:   template argument deduction/substitution failed:
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:262:28: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  262 |     template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \
      |                            ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:272:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_T’
  272 | CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Scalar)
      | ^~~~~~~~~~~~~~~~~~~~~
template.cpp:15:48: note:   mismatched types ‘cv::Mat_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:3291,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/operations.hpp:255:22: note: candidate: ‘template<class _Tp> const cv::Mat_<_Tp>& cv::operator+=(const cv::Mat_<_Tp>&, const Scalar&)’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:263:28: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  263 |     template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, const A, B)
      |                            ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:272:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_T’
  272 | CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Scalar)
      | ^~~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:22: note:   template argument deduction/substitution failed:
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:263:28: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  263 |     template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, const A, B)
      |                            ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:272:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_T’
  272 | CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Scalar)
      | ^~~~~~~~~~~~~~~~~~~~~
template.cpp:15:48: note:   mismatched types ‘const cv::Mat_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:3291,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/operations.hpp:255:22: note: candidate: ‘template<class _Tp> cv::Mat_<_Tp>& cv::operator+=(cv::Mat_<_Tp>&, const cv::Mat_<_Tp>&)’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:262:28: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  262 |     template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \
      |                            ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:273:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_T’
  273 | CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat_<_Tp>)
      | ^~~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:22: note:   template argument deduction/substitution failed:
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:262:28: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  262 |     template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, A, B) \
      |                            ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:273:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_T’
  273 | CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat_<_Tp>)
      | ^~~~~~~~~~~~~~~~~~~~~
template.cpp:15:48: note:   mismatched types ‘cv::Mat_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:3291,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/operations.hpp:255:22: note: candidate: ‘template<class _Tp> const cv::Mat_<_Tp>& cv::operator+=(const cv::Mat_<_Tp>&, const cv::Mat_<_Tp>&)’
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:263:28: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  263 |     template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, const A, B)
      |                            ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:273:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_T’
  273 | CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat_<_Tp>)
      | ^~~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:255:22: note:   template argument deduction/substitution failed:
  255 |     static inline A& operator op (A& a, const B& b) { cvop; return a; }
      |                      ^~~~~~~~
opencv2/core/operations.hpp:263:28: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR1’
  263 |     template<typename _Tp> CV_MAT_AUG_OPERATOR1(op, cvop, const A, B)
      |                            ^~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:273:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_T’
  273 | CV_MAT_AUG_OPERATOR_T(+=, cv::add(a,b,a), Mat_<_Tp>, Mat_<_Tp>)
      | ^~~~~~~~~~~~~~~~~~~~~
template.cpp:15:48: note:   mismatched types ‘const cv::Mat_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:3291,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/operations.hpp:266:59: note: candidate: ‘template<class _Tp, int m, int n> cv::Mat& cv::operator+=(cv::Mat&, const cv::Matx<_Tp, m, n>&)’
  266 |     template<typename _Tp, int m, int n> static inline A& operator op (A& a, const Matx<_Tp,m,n>& b) { cvop; return a; } \
      |                                                           ^~~~~~~~
opencv2/core/operations.hpp:274:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_TN’
  274 | CV_MAT_AUG_OPERATOR_TN(+=, cv::add(a,Mat(b),a), Mat)
      | ^~~~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:266:59: note:   template argument deduction/substitution failed:
  266 |     template<typename _Tp, int m, int n> static inline A& operator op (A& a, const Matx<_Tp,m,n>& b) { cvop; return a; } \
      |                                                           ^~~~~~~~
opencv2/core/operations.hpp:274:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_TN’
  274 | CV_MAT_AUG_OPERATOR_TN(+=, cv::add(a,Mat(b),a), Mat)
      | ^~~~~~~~~~~~~~~~~~~~~~
template.cpp:15:24: note:   cannot convert ‘(& m)->cv::Mat::at<unsigned char>(y, x)’ (type ‘unsigned char’) to type ‘cv::Mat&’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |     ~~~~~~~~~~~~~~~~~~~^~~~~
In file included from opencv2/core.hpp:3291,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/operations.hpp:267:65: note: candidate: ‘template<class _Tp, int m, int n> const cv::Mat& cv::operator+=(const cv::Mat&, const cv::Matx<_Tp, m, n>&)’
  267 |     template<typename _Tp, int m, int n> static inline const A& operator op (const A& a, const Matx<_Tp,m,n>& b) { cvop; return a; }
      |                                                                 ^~~~~~~~
opencv2/core/operations.hpp:274:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_TN’
  274 | CV_MAT_AUG_OPERATOR_TN(+=, cv::add(a,Mat(b),a), Mat)
      | ^~~~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:267:65: note:   template argument deduction/substitution failed:
  267 |     template<typename _Tp, int m, int n> static inline const A& operator op (const A& a, const Matx<_Tp,m,n>& b) { cvop; return a; }
      |                                                                 ^~~~~~~~
opencv2/core/operations.hpp:274:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_TN’
  274 | CV_MAT_AUG_OPERATOR_TN(+=, cv::add(a,Mat(b),a), Mat)
      | ^~~~~~~~~~~~~~~~~~~~~~
template.cpp:15:24: note:   cannot convert ‘(& m)->cv::Mat::at<unsigned char>(y, x)’ (type ‘unsigned char’) to type ‘const cv::Mat&’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |     ~~~~~~~~~~~~~~~~~~~^~~~~
In file included from opencv2/core.hpp:3291,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/operations.hpp:266:59: note: candidate: ‘template<class _Tp, int m, int n> cv::Mat_<_Tp>& cv::operator+=(cv::Mat_<_Tp>&, const cv::Matx<_Tp, m, n>&)’
  266 |     template<typename _Tp, int m, int n> static inline A& operator op (A& a, const Matx<_Tp,m,n>& b) { cvop; return a; } \
      |                                                           ^~~~~~~~
opencv2/core/operations.hpp:275:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_TN’
  275 | CV_MAT_AUG_OPERATOR_TN(+=, cv::add(a,Mat(b),a), Mat_<_Tp>)
      | ^~~~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:266:59: note:   template argument deduction/substitution failed:
  266 |     template<typename _Tp, int m, int n> static inline A& operator op (A& a, const Matx<_Tp,m,n>& b) { cvop; return a; } \
      |                                                           ^~~~~~~~
opencv2/core/operations.hpp:275:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_TN’
  275 | CV_MAT_AUG_OPERATOR_TN(+=, cv::add(a,Mat(b),a), Mat_<_Tp>)
      | ^~~~~~~~~~~~~~~~~~~~~~
template.cpp:15:48: note:   mismatched types ‘cv::Mat_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^
In file included from opencv2/core.hpp:3291,
                 from opencv2/opencv.hpp:52,
                 from template.cpp:1:
opencv2/core/operations.hpp:267:65: note: candidate: ‘template<class _Tp, int m, int n> const cv::Mat_<_Tp>& cv::operator+=(const cv::Mat_<_Tp>&, const cv::Matx<_Tp, m, n>&)’
  267 |     template<typename _Tp, int m, int n> static inline const A& operator op (const A& a, const Matx<_Tp,m,n>& b) { cvop; return a; }
      |                                                                 ^~~~~~~~
opencv2/core/operations.hpp:275:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_TN’
  275 | CV_MAT_AUG_OPERATOR_TN(+=, cv::add(a,Mat(b),a), Mat_<_Tp>)
      | ^~~~~~~~~~~~~~~~~~~~~~
opencv2/core/operations.hpp:267:65: note:   template argument deduction/substitution failed:
  267 |     template<typename _Tp, int m, int n> static inline const A& operator op (const A& a, const Matx<_Tp,m,n>& b) { cvop; return a; }
      |                                                                 ^~~~~~~~
opencv2/core/operations.hpp:275:1: note: in expansion of macro ‘CV_MAT_AUG_OPERATOR_TN’
  275 | CV_MAT_AUG_OPERATOR_TN(+=, cv::add(a,Mat(b),a), Mat_<_Tp>)
      | ^~~~~~~~~~~~~~~~~~~~~~
template.cpp:15:48: note:   mismatched types ‘const cv::Mat_<_Tp>’ and ‘unsigned char’
   15 |     m.at<unsigned char>(y,x) += cv::Vec3b(1,1,1);
      |                                                ^

Parallelität

Im Jahre 2020:

Algorithmische Optimierung

Beispiel: Bedarfsauswertung


./bba --input lena.pgm --brightness 0.5 --drop
      
Erstes Ziel der Optimierung sollte immer der Algorithmus sein.