Blob depth should be CV_32F or CV_8U

asked 2020-02-24 01:35:55 -0600

krjeev gravatar image

updated 2020-02-24 05:27:22 -0600

I am getting following error in metod blobFromImage:

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.0.0) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\dnn\src\dnn.cpp:134: error: (-2:Unspecified error) in function 'void __cdecl cv::dnn::dnn4_v20180917::blobFromImages(const class cv::_InputArray &,const class cv::_OutputArray &,double,class cv::Size_<int>,const class cv::Scalar_<double> &,bool,bool,int)'
> Blob depth should be CV_32F or CV_8U:
>     'ddepth == CV_32F || ddepth == CV_8U'
> where
>     'ddepth' is 187104008 (CV_8UC354)
]

when I tried to convert color to BGR/RGB using cvtColor, I got error as "cvtcolr not not supported for video mat objects".

My code is as below:

public static void main(String[] args) throws InterruptedException {
        System.load("C:/Sanjeev/softwares/OpenCV/opencv400/opencv/build/java/x64/opencv_java400.dll"); // Load the openCV 4.0 dll //
        String modelWeights = "C:/Users/sanjeevk/Desktop/solrTest/HandleVideo/yolov3.weights"; //Download and load only wights for YOLO , this is obtained from official YOLO site//
        String modelConfiguration = "C:/Users/sanjeevk/Desktop/solrTest/HandleVideo/yolov3.cfg.txt";//Download and load cfg file for YOLO , can be obtained from official site//
        String filePath = "C:/Users/sanjeevk/Desktop/solrTest/HandleVideo/23.mp4"; //My video  file to be analysed//
        VideoCapture cap = new VideoCapture(filePath);// Load video using the videocapture method//
        cap.set(Videoio.CAP_PROP_FRAME_WIDTH, 288); // width
        cap.set(Videoio.CAP_PROP_FRAME_HEIGHT, 288); // height

        Mat frame = new Mat(288, 288, CvType.CV_32F); // define a matrix to extract and store pixel info from video//
        Mat dst = new Mat ();
        //cap.read(frame);
        JFrame jframe = new JFrame("Video"); // the lines below create a frame to display the resultant video with object detection and localization//
        JLabel vidpanel = new JLabel();
        jframe.setContentPane(vidpanel);
        jframe.setSize(600, 600);
        jframe.setVisible(true);// we instantiate the frame here//


        Net net = Dnn.readNetFromDarknet(modelConfiguration, modelWeights); //OpenCV DNN supports models trained from various frameworks like Caffe and TensorFlow. It also supports various networks architectures based on YOLO//
        //Thread.sleep(5000);

        //Mat image = Imgcodecs.imread("D:\\yolo-object-detection\\yolo-object-detection\\images\\soccer.jpg");
        Size sz = new Size(288,288);

        List<Mat> result = new ArrayList<>();
        List<String> outBlobNames = getOutputNames(net);

        while (true) {
            if (cap.read(frame)) {

                Mat blob = Dnn.blobFromImage(frame, 1.0, sz, new Scalar(104.0, 117.0, 123.0, 0), false, false); // We feed one frame of video into the network at a time, we have to convert the image to a blob. A blob is a pre-processed image that serves as the input.//
                net.setInput(blob);
                net.forward(result, outBlobNames); //Feed forward the model to get output //
                // outBlobNames.forEach(System.out::println);
                // result.forEach(System.out::println);

                float confThreshold = 0.6f; //Insert thresholding beyond which the model will detect objects//
                List<Integer> clsIds = new ArrayList<>();
                List<Float> confs = new ArrayList<>();
                List<Rect> rects = new ArrayList<>();
                for (int i = 0; i < result.size(); ++i)
                {
                    // each row is a candidate detection, the 1st 4 numbers are
                    // [center_x, center_y, width, height], followed by (N-4) class probabilities
                    Mat level = result.get(i);
                    for (int j = 0; j < level.rows(); ++j)
                    {
                        Mat row ...
(more)
edit retag flag offensive close merge delete

Comments

Your code does not call cvtColor anywhere...

mvuori gravatar imagemvuori ( 2020-02-24 05:05:21 -0600 )edit

yes, thats the point, If I do, it throws error. Anyway thats not the point. Point here is what I am missing here that throws error.

krjeev gravatar imagekrjeev ( 2020-02-24 05:23:23 -0600 )edit