title: Invalid number of channels in input image
body: <p>I am receiving an error when running my program, I think specifically about color manipulation in the OpenCV library.</p>
  
  <p>I'm trying to build a program that takes a video feed from a Raspberry Pi camera and analyze it. I want to find the brightest point in the video and calculate the distance and angle the point is at from the center of the video feed.</p>
  
  <p>The project I am doing has the camera pointed at the center of a dark box, with a moving point of light.</p>
  
  <p>I am using OpenCV 4.0.0 and C++ on a Raspberry Pi 3, as well as the <a href="https://github.com/cedricve/raspicam" rel="noreferrer">raspicam</a> library.</p>
  
  <p>I am taking pointers from <a href="https://www.pyimagesearch.com/2014/09/29/finding-brightest-spot-image-using-python-opencv/" rel="noreferrer">this</a> guide, but I am using C++ and a video feed instead of Python and a static image.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>    raspicam::RaspiCam_Cv Camera;
      cv::Mat image;
      cv::Mat gray;
      int nCount=100;
      int nR, nC;         // numRows, numCols
      cv::Point imgMid;
      Vect toCenter;
  
      // for recording brightest part of img
      double minVal, maxVal;
      cv::Point minLoc, maxLoc;
  
      Camera.set(cv::CAP_PROP_FORMAT, CV_8UC1);
  
      #ifdef DEBUG
      cout &lt;&lt; "Opening camera..." &lt;&lt; endl;
      if (!Camera.open()) {
          cerr &lt;&lt; "Error opening the camera" &lt;&lt; endl;
          return -1;
      }
      cout &lt;&lt; "Capturing " &lt;&lt; nCount &lt;&lt; " frames ...." &lt;&lt; endl;
      #endif
  
      for (int i=0; i&lt; nCount; i++) {
          Camera.grab();
          Camera.retrieve(image);
          nR = image.rows;
          nC = image.cols;
          imgMid.x = nC / 2;
          imgMid.y = nR / 2;
  
          // convert to grayscale image
          cv::cvtColor(image, gray, cv::COLOR_BGR2GRAY);
  
          // find x, y coord of brightest part of img
          cv::minMaxLoc(gray, &amp;minVal, &amp;maxVal, &amp;minLoc, &amp;maxLoc);
  
          // calculate vector to the center of the camera
          toCenter.first = distBtwn(imgMid.x, maxLoc.x, imgMid.y, maxLoc.y);
          toCenter.second = angle(imgMid.x, maxLoc.x, imgMid.y, maxLoc.y);
  </code></pre>
  
  <p>I expect the program to take a frame of the video feed, convert it to grayscale, find the brightest part of the frame, and finally do some calculations to find the distance to the center of the frame and angle of the point from the positive x-axis.</p>
  
  <p>This is the error</p>
  
  <p><img src="https://i.imgur.com/Ae8AsHq.jpg" alt=""></p>
  
  <p>I apologize for the phone camera, but I am working with somebody else in a different city, where they have the testing equipment (I am the coder) and this is what they sent me.</p>