Im using OpenCV in java, developing with eclipse 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 mysql DataBase to Mat type for comparison(template matching) ...
More info: I have a mysql table with columns: 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. Afaik you can't access a column of mysql with /server/home/user/mysql/image_table/mypicture.png , I'm writing this because of "guneykayim" 's suggestion. 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.
In other words how can I convert InputStream object to Mat object?
Thanks for reading.
inFile
? For exampleinFile = "networkpath/image.png"
. AFAIK you can read image like that. – guneykayimimshow
you can still try to read it with aVideoCapture
. Check docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture Videocapture can open "sources" from IP, including cameras, videos and image FILES! If your server doesnt provide the files, but binary image data directly, you might use it directly (but you will have to know the format! e.g. RGB24). Hard to tell what to do if you dont provide information about what kind of data you get from your server... – Micka