Ask Your Question
0

Java: Core.Pow: (-215:Assertion failed) depth == CV_32F || depth == CV_64F

asked 2020-03-17 15:01:25 -0600

Hello,

I use an astronomy software that is call firecapture and you can add you own plug-in to the software.

To help, to learn and because plugin has to be in java, I try to add the BRISQUE quality image evaluation. https://www.learnopencv.com/image-qua...

I am stuck at the begining with an error:

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.2.0) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\core\src\mathfuncs.cpp:1242: error: (-215:Assertion failed) depth == CV_32F || depth == CV_64F in function 'cv::pow'

/* premier essai de open CV et java*/

package HelloCv;

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

/**importation des classes**/

public class HelloCv {
    public static void main(String[] args){
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        String location = "resources/Poli.jpg";
        System.out.print("Convert the image at " + location + " in gray scale... ");
        Mat image = Imgcodecs.imread(location);
        Imgproc.cvtColor(image, image, Imgproc.COLOR_BGR2GRAY);
        Imgcodecs.imwrite("resources/Poli-gray.jpg", image);
        //nouvel objet de type mat
        Mat mu = new Mat(image.size(),CvType.CV_64F);
        //application d'un filtre gaussien et enregistrement dans l'objet mu
        Imgproc.GaussianBlur(image, mu, new Size(7, 7), 1.166);
        //mu square
        Mat mu_sq = new Mat(image.size(),CvType.CV_64F);
         mu_sq  = mu.mul(mu);
        // mu sigma
        Mat sigma = new Mat(image.size(), CvType.CV_64F);
        Mat sigma2 = new Mat(image.size(), CvType.CV_32F);
        sigma = image.mul(image);
        //gaussian blur
        Imgproc.GaussianBlur(sigma, sigma, new Size(7, 7), 1.166);
        Imgcodecs.imwrite("resources/Poli-gray2.jpg", sigma );
        Core.subtract(sigma,mu_sq,sigma);
        Core.sqrt(sigma, sigma2);
}
}

I have tried to put everything in CV_32F but the same error, I have tried with core.pow but the same issue...

Could you help me?

Thanks

edit retag flag offensive close merge delete

Comments

You should figure out where it happens (pow is not called directly in your code) and check the type of Mats there.

mvuori gravatar imagemvuori ( 2020-03-18 00:50:38 -0600 )edit

problem is most likely here:

sigma = image.mul(image);

(image is still CV_8U)

berak gravatar imageberak ( 2020-03-18 13:02:22 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-03-19 11:51:29 -0600

Hello,

pow comes from Core.sqrt(sigma, sigma2);

Using that (normalization),

Core.normalize(image, image, 0, 255, Core.NORM_MINMAX, CvType.CV_64F);

I solve the problem and found an other one

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-03-17 15:01:25 -0600

Seen: 1,271 times

Last updated: Mar 17 '20