Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Reading Image for Template Matching for Java

Im using OpenCV in java and the images are read this way for template matching.

String inFile = "C:/image.png";

Mat img = Highgui.imread(inFile);

This is nice but my images are not in my local computer. I should compare 2000 images on a server in mysql database. Saving 2000 images to my computer and then reading them does not make sense.

So what I need is that Highgui.imread(inFile) reads an image: Highgui.imread(Image inImage) or maybe Highgui.imread(File inFile) , I couldnt find the java source to edit modify. I need someway to convert my images which will be coming from the DB to Mat type for comparison(template matching) ....

Thanks for reading.

Reading Image for Template Matching for Java

Im using OpenCV in java and the images are read this way for template matching.

String inFile = "C:/image.png";

Mat img = Highgui.imread(inFile);

This is nice but my images are not in my local computer. I should compare 2000 images on a server in mysql database. Saving 2000 images to my computer and then reading them does not make sense.

So what I need is that Highgui.imread(inFile) reads an image: Highgui.imread(Image inImage) or maybe Highgui.imread(File inFile) , I couldnt find the java source to edit modify. I need someway to convert my images which will be coming from the DB to Mat type for comparison(template matching) .......

More info: I have a mysql table: ID, Name, Description, Image1, Image2. The type of Image1 and 2 columns are "mediumblob" and when you right click to the column Image1 or Image2 in MySQL Workbench I choose "Open Value in Editor" Then there are 3 Tabs, Binary, Text, Image, at Image my image is displayed perfectly. The type of Images are png. In the end I want to Compare Image1 with Image2. Image2 is inFile and Image1 is templateFile.

Thanks for reading.

Reading Image for Template Matching for Java

Im using OpenCV in java and the images are read this way for template matching.

String inFile = "C:/image.png";

Mat img = Highgui.imread(inFile);

This is nice but my images are not in my local computer. I should compare 2000 images on a server in mysql database. Saving 2000 images to my computer and then reading them does not make sense.

So what I need is that Highgui.imread(inFile) reads an image: Highgui.imread(Image inImage) or maybe Highgui.imread(File inFile) , I couldnt find the java source to edit modify. I need someway to convert my images which will be coming from the DB to Mat type for comparison(template matching) ...

More info: I have a mysql table: ID, Name, Description, Image1, Image2. The type of Image1 and 2 columns are "mediumblob" and when you right click to the column Image1 or Image2 in MySQL Workbench I choose "Open Value in Editor" Then there are 3 Tabs, Binary, Text, Image, at Image my image is displayed perfectly. The type of Images are png. In the end I want to Compare Image1 with Image2. Image2 is inFile and Image1 is templateFile.

Thanks for reading.

Reading Image for Template Matching for Java

Im using OpenCV in java and the images are read this way for template matching.

String inFile = "C:/image.png";

Mat img = Highgui.imread(inFile);

This is nice but my images are not in my local computer. I should compare 2000 images on a server in mysql database. Saving 2000 images to my computer and then reading them does not make sense.

So what I need is that Highgui.imread(inFile) reads an image: Highgui.imread(Image inImage) or maybe Highgui.imread(File inFile) , I couldnt find the java source to edit modify. I need someway to convert my images which will be coming from the DB to Mat type for comparison(template matching) ...

More info: I have a mysql table: ID, Name, Description, Image1, Image2. The type of Image1 and 2 columns are "mediumblob" and when you right click to the column Image1 or Image2 in MySQL Workbench I choose "Open Value in Editor" Then then there are 3 Tabs, tabs; Binary, Text, Image, at Image my image is displayed perfectly. The type of Images are png. In the end I want to Compare Image1 with Image2. Image2 is inFile and Image1 is templateFile.

Thanks for reading.

Reading Image for Template Matching for Java

Im using OpenCV in java and the images are read this way for template matching.

String inFile = "C:/image.png";

Mat img = Highgui.imread(inFile);

This is nice but my images are not in my local computer. I should compare 2000 images on a server in mysql database. Saving 2000 images to my computer and then reading them does not make sense.

So what I need is that Highgui.imread(inFile) reads an image: Highgui.imread(Image inImage) or maybe Highgui.imread(File inFile) , I couldnt find the java source to edit modify. I need someway to convert my images which will be coming from the DB to Mat type for comparison(template matching) ...

More info: I have a mysql table: ID, Name, Description, Image1, Image2. The type of Image1 and 2 columns are "mediumblob" and when you right click to the column Image1 or Image2 in MySQL Workbench I choose "Open Value in Editor" then there are 3 tabs; Binary, Text, Image, at Image my image is displayed perfectly. The type of Images are png. In the end I want to Compare Image1 with Image2. Image2 is inFile and Image1 is templateFile.

I'm sorry I thought my question was clear. I will try to rephrase it. I have a local computer and a server. The images are stored in the mysql database on server. I want to run an application from my local computer that retrieves/accesses 2 images on the server and then compares them via OpenCV template matching. So how Im planning to retrieve the images, havent tried yet but the plan is :

Blob imageBlob = resultSet.getBlob(yourBlobColumnIndex);
InputStream binaryStream = imageBlob.getBinaryStream(0, imageBlob.length());

Or

InputStream binaryStream = resultSet.getBinaryStream(yourBlobColumnIndex);

Or

try{
    Class.forName(driverName);
    con = DriverManager.getConnection(url+dbName,userName,password);
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("select image from image");
    int i = 0;
    while (rs.next()) {
        InputStream in = rs.getBinaryStream(1);
        OutputStream f = new FileOutputStream(new File("test"+i+".jpg"));
        i++;
        int c = 0;
        while ((c = in.read()) > -1) {
            f.write(c);
        }
        f.close();
        in.close();
    }
}catch(Exception ex){
    System.out.println(ex.getMessage());
}

My Question: I want to compare 2 images, I retrieved from the mysql database.

Highgui.imread();

This method expects a String but I want to give the InputStream or the OutputStream file... Like I said I don't want to save 2000 images on my local computer. I'm open for alternative ways as well.

Final Simplest Rephrasing : How can I use template matching of java OpenCV on 2 images stored on a mysql database.

Thanks for reading.