title: Assertion failed (scn == 3 || scn == 4) in void cv::cvtColor(cv::InputArray Android
body: <p>I am trying to convert a Mat to a grey scale value so I can get the number value of a pixel. I'm getting an "Assertion failed (scn == 3 || scn == 4) in void cv::cvtColor(cv::InputArray error" on android. I know I missed something but I don't know what it is.</p>
  
  <p>code</p>
  
  <pre><code>import android.nfc.Tag;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.SurfaceView;
  import android.hardware.camera2.CameraCaptureSession;
  
  import org.opencv.android.BaseLoaderCallback;
  import org.opencv.android.CameraBridgeViewBase;
  import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
  import org.opencv.android.JavaCameraView;
  import org.opencv.android.LoaderCallbackInterface;
  import org.opencv.android.OpenCVLoader;
  import org.opencv.core.CvType;
  import org.opencv.core.Mat;
  import org.opencv.core.MatOfKeyPoint;
  import org.opencv.core.MatOfPoint;
  import org.opencv.imgproc.Imgproc;
  import org.opencv.highgui.Highgui;
  
  
  public class testActivity extends AppCompatActivity implements CvCameraViewListener2 {
  
  private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
      @Override
  public void onManagerConnected(int status){
          switch (status){
              case LoaderCallbackInterface.SUCCESS:
              {
                  mOpenCvCameraView.enableView();
                  break;
              }
              default:
              {
                  super.onManagerConnected(status);
              }
          }
      }
  
  };
  private JavaCameraView mOpenCvCameraView;
  Mat bgrPixel;
  Mat grayPixel;
  Mat rgbMat;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_test);
  
      mOpenCvCameraView = (JavaCameraView) findViewById(R.id.testVideoView);
      mOpenCvCameraView.setMaxFrameSize(240,320);
      mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
      mOpenCvCameraView.setCvCameraViewListener(this);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      //getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      getSupportActionBar().hide();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  
  
  public void onDestroy() {
      super.onDestroy();
      if (mOpenCvCameraView != null)
          mOpenCvCameraView.disableView();
  }
  
  public void onResume() {
      super.onResume();
      if (!OpenCVLoader.initDebug()) {
          OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback);
      } else {
          mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
      }
  }
  
  
  
  @Override
  public void onPause() {
      super.onPause();
  
      if (mOpenCvCameraView != null)
          mOpenCvCameraView.disableView();
  }
  
  @Override
  public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
      if(rgbMat == null){
          rgbMat = inputFrame.rgba();
          bgrPixel= rgbMat.submat(1,1,2,2).clone();
          grayPixel = new Mat();
          Imgproc.cvtColor(bgrPixel, grayPixel, Imgproc.COLOR_BGR2GRAY,1);
      }
      rgbMat= inputFrame.rgba();
      return rgbMat;
  }
  
  
  @Override
  public void onCameraViewStarted(int width, int height) {
  
  }
  
  @Override
  public void onCameraViewStopped() {
      bgrPixel.release();
      grayPixel.release();
      rgbMat.release();
  }
  
  
  }
  </code></pre>
  
  <p>log cat</p>
  
  <pre><code>08-18 14:44:37.649  17571-17884/bluemage.systems.displaylatencytester E/cv::error()﹕ OpenCV Error: Assertion failed (scn == 3 || scn == 4) in void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/color.cpp, line 3737
  08-18 14:44:37.650  17571-17884/bluemage.systems.displaylatencytester E/org.opencv.imgproc﹕ imgproc::cvtColor_10() caught cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/color.cpp:3737: error: (-215) scn == 3 || scn == 4 in function void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int)
  08-18 14:44:37.659  17571-17884/bluemage.systems.displaylatencytester E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-4081
  Process: bluemage.systems.displaylatencytester, PID: 17571
  CvException [org.opencv.core.CvException: cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/imgproc/src/color.cpp:3737: error: (-215) scn == 3 || scn == 4 in function void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int)
  ]
          at org.opencv.imgproc.Imgproc.cvtColor_0(Native Method)
          at org.opencv.imgproc.Imgproc.cvtColor(Imgproc.java:4244)
          at bluemage.systems.displaylatencytester.testActivity.onCameraFrame(testActivity.java:117)
          at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:387)
          at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:328)
          at java.lang.Thread.run(Thread.java:818)
  </code></pre>