title: OpenCV scalar used with template programming causes compilation error
body: <p>I am on Ubuntu 16.04 with the latest OpenCV from trunk and gcc 5.4.</p>
  
  <p>I am having some trouble to understand why the below code cannot be compiled</p>
  
  <pre><code>template &lt;typename T&gt;
  void Func2(const cv::Scalar clr, cv::Mat &amp;img){
    img.at&lt;T&gt;(0, 0) = clr;
  }
  
  void Func1(const bool flag, const cv::Scalar clr, cv::Mat &amp;img){
    if (flag == 1){
      Func2&lt;cv::Vec4b&gt;(clr, img);
    }
    else{
      Func2&lt;cv::Vec3b&gt;(clr, img);
    }
  }
  
  int main(){
    cv::Mat img = cv::Mat(100, 100, CV_8UC4, cv::Scalar(1,1,1,1));
    cv::Scalar clr = cv::Scalar(0, 0, 0, 0);
  
    Func1(1, clr, img);
  
    return 0;
  }
  </code></pre>
  
  <p>The compilation error is </p>
  
  <blockquote>
    <p>In instantiation of <code>void Func2(cv::Scalar, cv::Mat&amp;) [with T =
    cv::Vec&lt;unsigned char, 3&gt;; cv::Scalar = cv::Scalar_&lt;double&gt;]</code>: required from here</p>
    
    <p>error: no match for <code>operator=</code> (operand types are <code>cv::Vec&lt;unsigned
    char, 3&gt;</code> and <code>const Scalar {aka const cv::Scalar_&lt;double&gt;}</code>)<br>
    <code>img.at&lt;T&gt;(0, 0) = clr;
                       ^</code></p>
    
    <p>/usr/local/include/opencv2/core/matx.hpp:305:38: note: candidate:
    <code>constexpr cv::Vec&lt;unsigned char, 3&gt;&amp; cv::Vec&lt;unsigned char,
    3&gt;::operator=(const cv::Vec&lt;unsigned char, 3&gt;&amp;)  template&lt;typename
    _Tp, int cn&gt; class Vec : public Matx&lt;_Tp, cn, 1&gt;
                                          ^</code> <br> /usr/local/include/opencv2/core/matx.hpp:305:38: note:   no known
    conversion for argument 1 from <code>const Scalar {aka const
    cv::Scalar_&lt;double&gt;}</code> to <code>const cv::Vec&lt;unsigned char, 3&gt;&amp;</code></p>
  </blockquote>
  
  <p>I was thinking it might be that the type of <code>cv::Scalar</code> needs to be matched up correctly but even the below code compiles without a problem</p>
  
  <pre><code>int main(){
    cv::Mat img = cv::Mat(100, 100, CV_8UC4, cv::Scalar(1,1,1,1));
    cv::Scalar clr = cv::Scalar(0, 0, 0);
  
    img.at&lt;cv::Vec4b&gt;(0, 0) = clr // still compiles but has runtime error
  
    return 0;
  }
  </code></pre>