Ask Your Question
0

OpenCV(3.4.11) Error: Unspecified error (Number of input channels should be multiple of 3 but got 4

asked 2020-08-29 06:06:37 -0600

HaniN gravatar image

I mauising opencv 3.4.11 for android. I get this error when i used the forward of Net function:

        Mat imageBlob = Dnn.blobFromImage(frame, 0.00392, new Size(416,416),new Scalar(0, 0, 0),/*swapRB*/false, /*crop*/false);
        tinyV4.setInput(imageBlob);

        /* the result */
        java.util.List<Mat> result = new java.util.ArrayList<Mat>(2);
        List<String> outputLayers = new java.util.ArrayList<>();
        /* the outputs layers are 30 and 37*/
        outputLayers.add(0, "yolo_30");
        outputLayers.add(1, "yolo_37");
        /*we are looking for layers yolo30 and yolo37, and we want to save them into result */
        tinyV4.forward(result, outputLayers);

The full error: OpenCV(3.4.11) Error: Unspecified error (Number of input channels should be multiple of 3 but got 4) in virtual bool cv::dnn::ConvolutionLayerImpl::getMemoryShapes(const std::vector<std::vector<int> >&, int, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&) const, file /build/3_4_pack-android/opencv/modules/dnn/src/layers/convolution_layer.cpp, line 306 [ERROR:0] input[0] = [ 1 4 510 510 ] [ERROR:0] blobs[0] = CV_32FC1 [ 32 3 3 3 ] [ERROR:0] Exception message: OpenCV(3.4.11) /build/3_4_pack-android/opencv/modules/dnn/src/layers/convolution_layer.cpp:306: error: (-2:Unspecified error) Number of input channels should be multiple of 3 but got 4 in function 'virtual bool cv::dnn::ConvolutionLayerImpl::getMemoryShapes(const std::vector<std::vector<int> >&, int, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&) const' E/org.opencv.dnn: dnn::forward_14() caught cv::Exception: OpenCV(3.4.11) /build/3_4_pack-android/opencv/modules/dnn/src/layers/convolution_layer.cpp:306: error: (-2:Unspecified error) Number of input channels should be multiple of 3 but got 4 in function 'virtual bool cv::dnn::ConvolutionLayerImpl::getMemoryShapes(const std::vector<std::vector<int> >&, int, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&) const'

I tried to change the size to to 512X512, 1024x980, it not helped.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-08-29 07:19:44 -0600

updated 2020-08-29 07:26:49 -0600

i think you read from camera a RGBA image and need to convert it to RGB

see mobilenet-objdetect sample

edit flag offensive delete link more

Comments

Thanks, it works after adding conversion: Imgproc.cvtColor(frame, frame, Imgproc.COLOR_RGBA2RGB);

HaniN gravatar imageHaniN ( 2020-08-31 00:22:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-08-29 06:06:37 -0600

Seen: 4,866 times

Last updated: Aug 29 '20