AI-Based Library Management System using Image
Recognition
Submitted by
MEERA ELDHO RA2211028020003
M.N.SWASTHIKA SAHANA RA2211028020042
AVANI MALETHA RA2211028020051
Under the guidance of
Dr. S. Raja Ratna
(Associate Professor, Department of Computer Science and Engineering)
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY RAMAPURAM, CHENNAI 600089
ABSTRACT
This project describes a beginner-friendly Library Management System that uses imagebased recognition (OCR/vision) to identify book titles and authors from photos and stores
the extracted information in a database. The document includes a simple Python
implementation (using Tesseract OCR and sqlite3) and a simple Java implementation
(using Tess4J and SQLite JDBC). Both implementations are written to be easy-to-follow
for students, with explanations and sample code for running and testing.
TABLE OF CONTENTS
1. Introduction
2. Existing System
3. Design (Block diagram, ER diagram, Methodology)
4. Implementation (Python and Java)
5. Results and Discussion
6. Conclusion
References
CHAPTER 1 - INTRODUCTION
1.1 Introduction
Libraries are moving toward automation and digitization. This project demonstrates a
simple Library Management System that leverages image recognition to capture book
information from photos: title, author, and ISBN if visible. The system stores these
details in a local database and provides a small command-line interface for beginners.
1.2 Problem Statement
Manually cataloging large numbers of physical books is time-consuming and error-prone.
Using mobile photos and OCR/vision automates capturing metadata and speeds up
cataloging.
1.3 Objectives
- Provide a simple pipeline to extract book title and author from an image.
- Store the extracted data in a local database (sqlite) with timestamps.
- Provide beginner-friendly code in Python and Java with clear explanations.
1.4 Scope & Motivation
This project targets students and small libraries. It focuses on core concepts: image
capture, OCR, simple matching, and database storage. Production systems use more
robust models (book-cover recognition, neural embeddings, online APIs), but this project
is intentionally simple.
CHAPTER 2 - EXISTING SYSTEM
Existing library systems often rely on manual entry, barcode scanning, or integrated APIs
(WorldCat, Google Books). Barcode scanning requires barcodes to be readable; manual
entry is slow. Modern approaches use cover-image recognition (deep learning) or ISBN
lookup APIs.
CHAPTER 3 - DESIGN
3.1 Block Diagram
Camera/Image -> Preprocessing -> OCR / Vision model -> Parse Title/Author ->
Database (sqlite) -> UI
3.2 ER Diagram (simple)
Entities:
- Book(id, title, author, isbn, image_path, added_on)
- User(optional for future work)
Relationships: Books are catalog records stored in the database.
3.3 Methodology
Steps:
1. Capture photo of a book cover or page containing title/author.
2. Preprocess image (resize, grayscale, threshold).
3. Run OCR (Tesseract) to get text.
4. Parse text to find title & author heuristically.
5. Store record in sqlite database.
CHAPTER 4 - IMPLEMENTATION
This chapter provides two beginner-friendly implementations: Python (recommended for
quick prototyping) and Java (for students who prefer Java). Both use Tesseract OCR
(open-source) and sqlite for local storage.
4.1 Python Implementation
Overview:
- Libraries used: pytesseract, Pillow (PIL), OpenCV (optional), sqlite3.
- Workflow: load image -> preprocess -> run pytesseract -> parse -> insert into sqlite.
Requirements (install):
- Python 3.8+
- pip install pytesseract pillow opencv-python
- Install Tesseract OCR engine on the system (e.g., apt install tesseract-ocr on Linux or
download for Windows).
Python Code (simple):
import sqlite3
import pytesseract
from PIL import Image, ImageOps
import datetime
import re
import sys
# If Tesseract is not in your PATH, uncomment and set the tesseract_cmd:
# pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
DB = 'library.db'
def init_db():
conn = sqlite3.connect(DB)
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS books
(id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, author TEXT, isbn TEXT, image_path
TEXT, added_on TEXT)''')
conn.commit()
conn.close()
def preprocess_image(path):
img = Image.open(path)
img = ImageOps.grayscale(img)
# simple resize for better OCR
img = img.resize((int(img.width * 1.5), int(img.height * 1.5)))
return img
def extract_text(img):
text = pytesseract.image_to_string(img)
return text
def parse_title_author(text):
# naive heuristics: look for lines with 'by' or treat first lines as title/author
lines = [l.strip() for l in text.splitlines() if l.strip()]
title = author = None
for i, line in enumerate(lines[:6]):
# look for "by Author Name"
m = re.search(r'by\s+(.+)', line, flags=re.IGNORECASE)
if m:
author = m.group(1).strip()
# title is probably the previous non-empty line if exists
title = lines[i-1] if i-1 >= 0 else None
break
if not title and lines:
title = lines[0]
if not author and len(lines) > 1:
author = lines[1]
# try to find an ISBN
isbn = None
m = re.search(r'ISBN(?:-1[03])?:?\s*([0-9Xx- ]{10,17})', text)
if m:
isbn = m.group(1).strip()
return title, author, isbn
def save_book(title, author, isbn, image_path):
conn = sqlite3.connect(DB)
c = conn.cursor()
c.execute("INSERT INTO books (title, author, isbn, image_path, added_on) VALUES (?, ?, ?, ?, ?)",
(title, author, isbn, image_path, datetime.datetime.now().isoformat()))
conn.commit()
conn.close()
def main(image_path):
init_db()
img = preprocess_image(image_path)
text = extract_text(img)
title, author, isbn = parse_title_author(text)
print("=== OCR TEXT ===")
print(text)
print("\nParsed:")
print("Title:", title)
print("Author:", author)
print("ISBN:", isbn)
save_book(title, author, isbn, image_path)
print("Saved to database 'library.db'.")
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: python catalog_book.py path/to/book_image.jpg")
else:
main(sys.argv[1])
Explanation (Python):
- init_db(): creates an sqlite database and a books table.
- preprocess_image(): converts to grayscale and resizes — simple steps to improve OCR
accuracy.
- extract_text(): calls pytesseract to get the text from image.
- parse_title_author(): uses simple regex/heuristics to extract title, author, and ISBN. This
is intentionally naïve; real systems use trained models.
- save_book(): inserts the parsed record into the sqlite database.
- Running: python catalog_book.py image.jpg
Notes:
- OCR accuracy depends on image quality. Better lighting, straight angle, and higher
resolution improve results.
- For better results consider using specialized book-cover recognition models, CLIP
image-captioning, or calling external APIs like Google Books to verify metadata.
4.2 Java Implementation
Overview:
- Libraries: Tess4J (a Java wrapper for Tesseract), SQLite JDBC.
- Workflow similar to Python: load image, OCR via Tess4J, parse, insert into sqlite.
Requirements:
- JDK 11+
- Add Tess4J and sqlite-jdbc to your project's dependencies (Maven/Gradle or add JARs).
- Install Tesseract on system and ensure tessdata is available.
Java Code (simple):
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
import java.sql.*;
import java.time.LocalDateTime;
import java.util.regex.*;
public class CatalogBookJava {
static final String DB = "jdbc:sqlite:library_java.db";
public static void initDb() throws SQLException {
Connection conn = DriverManager.getConnection(DB);
String sql = "CREATE TABLE IF NOT EXISTS books (id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT, author TEXT, isbn TEXT, image_path TEXT, added_on TEXT)";
conn.createStatement().execute(sql);
conn.close();
}
public static String doOCR(String imagePath) throws Exception {
Tesseract t = new Tesseract();
// If tessdata is in custom folder: t.setDatapath("C:/Tesseract-OCR/tessdata");
BufferedImage img = ImageIO.read(new File(imagePath));
return t.doOCR(img);
}
public static String[] parseTitleAuthor(String text) {
String[] result = new String[3]; // title, author, isbn
String[] lines = text.split(\"\\r?\\n\");
String title = null, author = null, isbn = null;
for (int i = 0; i < Math.min(lines.length, 6); i++) {
String line = lines[i].trim();
if (line.toLowerCase().contains(\" by \")) {
// simple split on 'by'
String[] parts = line.split(\"(?i)\\sby\\s\", 2);
if (parts.length == 2) {
author = parts[1].trim();
title = i > 0 ? lines[i-1].trim() : null;
break;
}
}
}
if (title == null && lines.length > 0) title = lines[0].trim();
if (author == null && lines.length > 1) author = lines[1].trim();
Pattern p = Pattern.compile(\"ISBN(?:-1[03])?:?\\s*([0-9Xx- ]{10,17})\");
Matcher m = p.matcher(text);
if (m.find()) isbn = m.group(1).trim();
result[0] = title; result[1] = author; result[2] = isbn;
return result;
}
public static void saveBook(String title, String author, String isbn, String imagePath) throws SQLException {
Connection conn = DriverManager.getConnection(DB);
String sql = \"INSERT INTO books(title, author, isbn, image_path, added_on) VALUES (?, ?, ?, ?, ?)\"];
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, title);
ps.setString(2, author);
ps.setString(3, isbn);
ps.setString(4, imagePath);
ps.setString(5, LocalDateTime.now().toString());
ps.executeUpdate();
ps.close();
conn.close();
}
public static void main(String[] args) throws Exception {
if (args.length < 1) {
System.out.println(\"Usage: java CatalogBookJava path/to/image.jpg\");
return;
}
initDb();
String text = doOCR(args[0]);
System.out.println(\"=== OCR TEXT ===\\n\" + text);
String[] parsed = parseTitleAuthor(text);
System.out.println(\"Parsed:\\nTitle: \" + parsed[0] + \"\\nAuthor: \" + parsed[1] + \"\\nISBN: \" + parsed[2]);
saveBook(parsed[0], parsed[1], parsed[2], args[0]);
System.out.println(\"Saved to database 'library_java.db'.\");
}
}
Explanation (Java):
- initDb(): uses SQLite JDBC to create database and table.
- doOCR(): uses Tess4J to call Tesseract and return extracted text.
- parseTitleAuthor(): same simple heuristics as Python to find title/author/ISBN.
- saveBook(): inserts the record into sqlite database using JDBC.
Notes:
- Add Tess4J and sqlite-jdbc to classpath. With Maven, add corresponding dependencies.
Ensure native Tesseract is installed on the system.
- Tess4J sometimes requires native libraries; when beginner problems occur, test
Tesseract from the command line to ensure it works first.
CHAPTER 5 - RESULTS AND DISCUSSION
Testing steps:
1. Take clear photos of book covers or first pages containing title and author.
2. Run the Python script: python catalog_book.py cover.jpg
3. Run the Java program similarly.
Expected outcome:
- OCR output printed on console.
- Parsed title, author, ISBN printed.
- Record saved into sqlite database (library.db or library_java.db).
Limitations:
- Heuristics may fail for complex cover designs, stylized fonts, or language differences.
- For production, use a trained image-search model, integrate barcode scanning, or use
online APIs to verify metadata.
Improvements:
- Use a small fine-tuned classifier for book-cover recognition.
- Use fuzzy-match to query Google Books or Open Library for canonical metadata.
- Add a simple GUI (Tkinter/JavaFX) for ease of use.
CHAPTER 6 - CONCLUSION
This beginner-friendly project demonstrates how to build a simple Library Management
System that leverages OCR to capture book metadata from photos and store it in a local
database. The included Python and Java implementations are intentionally simple to help
students understand the core pipeline: image -> OCR -> parse -> store. Further work can
extend accuracy and usability by adding cover-image models, APIs, and a nicer UI.
REFERENCES
Tesseract OCR - https://github.com/tesseract-ocr/tesseract
pytesseract Python wrapper - https://pypi.org/project/pytesseract/
Tess4J (Java wrapper) - https://tess4j.sourceforge.net/
SQLite - https://www.sqlite.org/
Open Library / Google Books APIs for metadata lookup
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )