Ask Your Question
0

hi, can be help me, with this "assertion failed ((img.depth()==cv_8U|| img.depth()==cv_32F)&&img.type()==templ.type())"

asked 2017-04-25 13:26:17 -0600

I'm working on a project in java, I'm using the match template. And gives me that error. anexo el codigo que tengo del metodo

public void MatchingMethod1() { Connection conect;

    Mat template = frame;
    try {
        conect = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/imagen", "root", "12345");
        PreparedStatement pps = (PreparedStatement) conect.prepareStatement("SELECT imagen FROM imagenes");
        rst = pps.executeQuery();
        while (rst.next()) {

           Blob imagen = (Blob) rst.getBlob("imagen");

            Mat imagenO = Highgui.imread(imagen.toString());


            int result_cols = -imagenO.cols() + template.cols() + 1;
            int result_rows = -imagenO.rows() + template.rows() + 1;

            Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1);

            Imgproc.matchTemplate(imagenO, template, result, Imgproc.TM_SQDIFF_NORMED);
            Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
            MinMaxLocResult mmr = Core.minMaxLoc(result);
            double threashhold = 0.10;
            if (mmr.maxVal > threashhold) {

                JOptionPane.showMessageDialog(null, "Encontrado");
                break;
            } else {
                JOptionPane.showMessageDialog(null, "No coincidencias suficientes");
            }

        }
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

Any help is welcome

edit retag flag offensive close merge delete

Comments

i can only guess, but rst.getBlob("imagen"); will probably return an image "in memory" , not "on disk"

is it a case of using imdecode() instead of imread() here ? (again, there will be nothing written to your hard your disk, given the current code)

again, - my guess is: Mat imagenOis just empty/invalid. (please check !)

berak gravatar imageberak ( 2017-04-25 13:56:50 -0600 )edit

Could you explain how it would be to use imcode, please.

juan524 gravatar imagejuan524 ( 2017-04-25 18:24:35 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-04-26 00:49:07 -0600

berak gravatar image

updated 2017-04-26 00:59:29 -0600

http://docs.opencv.org/java/3.1.0/org...

i don't use java, so cannot test, but i guess, you have to extract a byte[] from your Blob , make a MatOfBytes from that, and then use imdecode()

also, imho you got image and template reversed (it looks like you're searching in the frame for some template from your database. if so, you need to swap image & template)

edit flag offensive delete link more

Comments

thank you... One more question, what I need is to compare an incoming image with those stored in the database, to allow entry to a place. Is there a way to do it different from the one I raise?

juan524 gravatar imagejuan524 ( 2017-04-26 13:20:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-04-25 13:26:17 -0600

Seen: 1,012 times

Last updated: Apr 26 '17