|
Hemant Chauhan Oodles

Hemant Chauhan (Backend-Lead Development)

Experience:5+ yrs

Hemant is an accomplished backend developer with extensive experience in software development. He possesses an in-depth understanding of various technologies and has a strong command over Java, Spring Boot, MySQL, Elasticsearch, Selenium with Java, GitHub/GitLab, HTML/CSS, and MongoDB. Hemant has worked on several related projects, including Tessaract OCR, Sikuli with Selenium Automation, Transleqo, and currently, SecureNow. He excels at managing trading bots, developing centralized exchanges, and has a creative mindset with exceptional analytical skills.

Hemant Chauhan Oodles
Hemant Chauhan
(Lead Development)

Hemant is an accomplished backend developer with extensive experience in software development. He possesses an in-depth understanding of various technologies and has a strong command over Java, Spring Boot, MySQL, Elasticsearch, Selenium with Java, GitHub/GitLab, HTML/CSS, and MongoDB. Hemant has worked on several related projects, including Tessaract OCR, Sikuli with Selenium Automation, Transleqo, and currently, SecureNow. He excels at managing trading bots, developing centralized exchanges, and has a creative mindset with exceptional analytical skills.

LanguageLanguages

DotENGLISH

Basic

DotHINDI

Fluent

Skills
Skills

DotManual Testing

80%

DotDatabase Testing

80%

DotJava

80%

DotGithub/Gitlab

100%

DotSelenium with Java

60%

DotAPI Testing

100%

DotMySQL

60%

DotSpring Boot

60%

DotHTML, CSS

60%
ExpWork Experience / Trainings / Internship

Jan 2020-Present

Lead Development

Gurgaon


Oodles Technologies

Gurgaon

Jan 2020-Present

EducationEducation

2017-2019

Dot

DIT

MCA-Java developer

certificateCertifications
Dot

Java and spring training

Ducat

Issued On

Aug 2019

Top Blog Posts
Introduction to Aws textract and how we use it for data extraction

 

Amazon Textract is an simple optical character recognition(OCR) service that automatically extracts text and information from scanned documents. The main Advantage of Amazon textract is you can easily get the information stored in tables and content of fields in forms.

 

The Result of Amazon textract is very accurate as compared to tesseract which is open source OCR engine. You cannot extract table cell and forms information using tesseract engine. Textract supports all types of image formats especially scans images. Using Amazon s3 bucket, textract also supports PDFs documents too. When you upload the document to Amazon textract it popup the message and ask that “ you have to create the amazon s3 bucket ” when you answer yes it automatically creates the s3 bucket on your amzaon s3 service and store that uploaded pdf into created s3 bucket.

 

In AWS Textract, we get three types of results:

 

1. RawText- In raw text all document data will be extracted. If the document have key value pairs then the resulting raw text is like “ key: value”.

2. Forms- If the document contain any form, then the resulting data is of form type(key value pair)

3. Tables: In this type, textract detect all tables form the document and extract tabular information per cell and also converts the resulting data into csv file when you download the results.

 

How we use Amazon Textract

 

1. Go to https://aws.amazon.com/textract/ sign In to the console of aws and click on get started with Amazon textract.

 

2. Click on try amazon textract. Now you can see upload document option, here you can upload any document.

 

3. After uploading ,In the right side you can see four option Raw text, Forms, Tables and Human review. Here you can see the extracted document data. You can also download the results using Download results option after extraction.

 

How we use Textract in python with a few lines of code.

 

1. Showing the document processing on local machine.

 

 import boto3  
 # Document  
 documentName = "OneKeyValue.png"  
 # Read document content  
 with open(documentName, 'rb') as document:  
   imageBytes = bytearray(document.read())  
 # Amazon Textract client  
 textract = boto3.client('textract')  
 # Call Amazon Textract  
 response = textract.detect_document_text(Document={'Bytes': imageBytes})  
 #print(response)  
 # Print detected text  
 for item in response["Blocks"]:  
   if item["BlockType"] == "LINE":  
     print ('\033[94m' + item["Text"] + '\033[0m')  

 

2. Showing processing the document in Amazon s3 bucket. Make sure before using s3 bucket you have to set your local system aws credentials and config file according to your s3 bucket configuration. Also make sure the document already save to your s3 bucket before running the script.

 

 import boto3  
 # Document  
 s3BucketName = "Your s3 bucket Name"  
 documentName = "document.jpg"  
 # Amazon Textract client  
 textract = boto3.client('textract')  
 # Call Amazon Textract  
 response = textract.detect_document_text(  
   Document={  
     'S3Object': {  
       'Bucket': s3BucketName,  
       'Name': documentName  
     }  
   })  
 #print(response)  
 # Print detected text  
 for item in response["Blocks"]:  
   if item["BlockType"] == "LINE":  
     print ('\033[94m' + item["Text"] + '\033[0m')  

 

3. Showing form (key/value) processing

 

 import boto3  
 from trp import Document  
 # Document  
 s3BucketName = "Your s3 bucket name"  
 documentName = "document.jpg"  
 # Amazon Textract client  
 textract = boto3.client('textract')  
 # Call Amazon Textract  
 response = textract.analyze_document(  
   Document={  
     'S3Object': {  
       'Bucket': s3BucketName,  
       'Name': documentName  
     }  
   },  
   FeatureTypes=["FORMS"])  
 #print(response)  
 doc = Document(response)  
 for page in doc.pages:  
   # Print fields  
   print("Fields:")  
   for field in page.form.fields:  
     print("Key: {}, Value: {}".format(field.key, field.value))  
   # Get field by key  
   print("\nGet Field by Key:")  
   key = "Phone Number:"  
   field = page.form.getFieldByKey(key)  
   if(field):  
     print("Key: {}, Value: {}".format(field.key, field.value))  
   # Search fields by key  
   print("\nSearch Fields:")  
   key = "address"  
   fields = page.form.searchFieldsByKey(key)  
   for field in fields:  
     print("Key: {}, Value: {}".format(field.key, field.value))  

 

4. Showing table processing

 

 import boto3  
 # Document  
 from python.trp import Document  
 s3BucketName = "Your s3 bucket name"  
 documentName = "document.jpg"  
 # Amazon Textract client  
 textract = boto3.client('textract')  
 # Call Amazon Textract  
 response = textract.analyze_document(  
   Document={  
     'S3Object': {  
       'Bucket': s3BucketName,  
       'Name': documentName  
     }  
   },  
   FeatureTypes=["TABLES"])  
 #print(response)  
 doc = Document(response)  
 for page in doc.pages:  
    # Print tables  
   for table in page.tables:  
     for r, row in enumerate(table.rows):  
       for c, cell in enumerate(row.cells):  
         print("Table[{}][{}] = {}".format(r, c, cell.text))  

 

5. Showing PDF document processing

 

 import boto3  
 import time  
 def startJob(s3BucketName, objectName):  
   response = None  
   client = boto3.client('textract')  
   response = client.start_document_text_detection(  
   DocumentLocation={  
     'S3Object': {  
       'Bucket': s3BucketName,  
       'Name': objectName  
     }  
   })  
   return response["JobId"]  
 def isJobComplete(jobId):  
   time.sleep(5)  
   client = boto3.client('textract')  
   response = client.get_document_text_detection(JobId=jobId)  
   status = response["JobStatus"]  
   print("Job status: {}".format(status))  
   while(status == "IN_PROGRESS"):  
     time.sleep(5)  
     response = client.get_document_text_detection(JobId=jobId)  
     status = response["JobStatus"]  
     print("Job status: {}".format(status))  
   return status  
 def getJobResults(jobId):  
   pages = []  
   time.sleep(5)  
   client = boto3.client('textract')  
   response = client.get_document_text_detection(JobId=jobId)  
   pages.append(response)  
   print("Resultset page recieved: {}".format(len(pages)))  
   nextToken = None  
   if('NextToken' in response):  
     nextToken = response['NextToken']  
   while(nextToken):  
     time.sleep(5)  
     response = client.get_document_text_detection(JobId=jobId, NextToken=nextToken)  
     pages.append(response)  
     print("Resultset page recieved: {}".format(len(pages)))  
     nextToken = None  
     if('NextToken' in response):  
       nextToken = response['NextToken']  
   return pages  
 # Document  
 s3BucketName = "Your s3 bucket name"  
 documentName = "document.pdf"  
 jobId = startJob(s3BucketName, documentName)  
 print("Started job with id: {}".format(jobId))  
 if(isJobComplete(jobId)):  
   response = getJobResults(jobId)  
 #print(response)  
 # Print detected text  
 for resultPage in response:  
   for item in resultPage["Blocks"]:  
     if item["BlockType"] == "LINE":  
       print ('\033[94m' + item["Text"] + '\033[0m')  

 

Elementry Authentication with Spring Security

Basic Authentication with Spring Security

In this article, you will learn how to secure RestApi's in a Spring Boot application using Spring Security.

Suppose you create some RestApi's( get all data, post data, getbyId ), but there is no username and password to access these Api's, anyone can access these API's easily. For solving this problem, we will implement basic authentication in our spring boot application.

Basic Authentication is a basic way of authentication and easy to implement in our application. There is some other authentication we use such as digest, OAuth(Open Authorization), and oauth2 authentication. Oauth2is the best choice, in this method user logs with username and password it generates the token then the user will forward this token to an authentication server, which will either reject or allow this authentication. There is the timing of the token expires.


Steps to implement Basic Authentication in spring-boot Application

1. To add security to our Spring Boot application, we need to add the security starter maven dependency:


<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-security</artifactId>

</dependency>

This is called the default security configuration. Previously, we used the separate configuration class for security purpose, but now using this dependency automatically include SecurityAutoConfiguration class.


2. We have to define the username and password in the application.properties file

spring.security.user.name= Your username

spring.security.user.password= Your password

If we don't define defined the password in this property file, then if we go to start the application it automatically generates the default password. We get a password in the console of the editor(eclipse or IntelliJ). Each time the application starts, the password will be different.

It looks like this in the console:

Using default security password: c8be15de-4488-4490-9dc6-fab3f91435c6

3. Suppose we have RestApi URL “/postuser” to post the data. Open postman provide Provide URI http://localhost:8080/postusers, click on a body, and provide required data according to your POJO class. You can also use get mapping too. When you click on Send it returns the Status: 401 Unauthorized.

This status tells us that our security authentication is working properly. Now we again go to postman click on Authentication, select the type of authentication Basic Auth and provide your username and password that you provide previously in the application properties file.

Then clicks on the Send button it returns Status: 201 Created means our data is successfully posted using spring security.

If you are using the default security configuration(without defining username and password in properties) the default username is the user and password you will get from a console. The main disadvantage of default security is every time the default password is changed when you restart the application.

We also disable this security auto-configuration and add our own configuration, we also add flexible configuration with multiple users and roles, here we need to add a configuration class.

 

An Introduction to Using Thymeleaf in Spring boot

This blog explains how Thymeleaf can be integrated with the Spring boot Framework and show you how to develop a simple Spring Boot application using Thymeleaf java library in which thymeleaf act as a template engine to display data on front end.

 

Spring framework is one of the leading frameworks in the JAVA world for developing reliable and high-quality Enterprise-level applications with zero XML configuration and embedded web server.

 

What is Thymeleaf?

 

Thymeleaf is a open-source Java library used to create a web application. It is a server-side Java template engine for both web or servlet based and standalone or nonweb applications .

It provides full integration with Spring Framework. Thymeleaf is very fast when compared with other popular template engines such as JSP. It is built on the concept of natural templates, we can easily open and display these template file normally in the browser. Jsp don't have capablity to do this.

By default, Thymeleaf comes with 6 templates namely:

 

XML

Valid XML

XHTML

Valid XHTML

HTML5

Legacy HTML5

 

Developers consider thymeleaf ideal for HTML5 web development because it provides more flexibility and easy to use than other templates.

 

 

How to integrate thymeleaf with spring boot

 

For a Spring Boot Thymeleaf web application, we have maven dependencies that we have to put on pom.xml file.

 

 <dependency>   
   <groupId>org.springframework.boot</groupId>  
   <artifactId>spring-boot-starter-web</artifactId>  
 </dependency>  
 <dependency>   
   <groupId>org.springframework.boot</groupId>  
   <artifactId>spring-boot-starter-thymeleaf</artifactId>  
 </dependency>  

 

Spring Boot configures template engine to read template files from the default template directory src/main/resources/templates.

 

Attributes in thymeleaf


 

Thymeleaf will read a template or html file and then it will read combine data and set the values according to fields of the model object.. We can handle this data in backend easily using attribute “@Model Attribute” annotation.

 

th:text=”${person.firstName}” tag attribute is used to display the value of model data

members like id, name etc.

If we talk about collection of objects then the th:each tag attribute can be used to iteration.

For example:

1.Here we define a pojo class with two fields-

 public class Person implements Serializable {  
 private String firstName;  
 private String lastName;  
 // standard getters and setters  
 }  

 

2. Define a controller and add a list of persons as model attribute


 

 List<Person> students = new ArrayList<Person>();  
 model.addAttribute("persons", persons);  

 

3. Finally we have a thymeleaf template html code in which we iterate the list and display both fields values.

 <tr th:each="person: ${persons}">  
 <td th:text="${person.firstName}" />  
 <td th:text="${person.lastName}" />  
 </tr>  

 

If we want handle user input with a simple form then th:action=”@{url}” , th:object=”${object}” and th:field=”*{name}” attributes are used. Action tag attribute is used to provide url of our spring boot rest api which we create in inside the controller class. Object tag attribute represents object in which the submit data will be bound. Field tag attribute is used for mapping the individual field present in the model class.

For example:

1. Thymleaf template with a simple submit form

 <form action="#" th:action="@{/savePerson}" th:object="${person}" method="post">  
 <tr>  
 <td><label th:text="#{person.firstName}" /></td>  
 <td><input type="text" th:field="*{firstName}" /></td>  
 </tr>  
 <tr>  
 <td><label th:text="#{person.lastName}" /></td>  
 <td><input type="text" th:field="*{lastName}" /></td>  
 </tr>  
 <tr>  
 <td><input type="submit" value="Submit" /></td>  
 </tr>  
 </table>  
 </form>  

 

2. Person controller for handling form submission

 

 @Controller  
 public class PersonController {  
 @RequestMapping(value = "/savePerson", method = RequestMethod.POST)  
 public String savePerson(@ModelAttribute Person person, BindingResult errors, Model model) {  
 }  
Process of integrating Spring boot and MongoDB

How to integrate Spring boot and mongodb

 

In this article, we will demonstrate how to connect Spring Data with Mongodb and create a small REST service with Spring Boot and MongoDB.

MongoDB is a open source and document-oriented NoSQL database that stores data in JSON form. The main advantage of using mongodb is it is used for high volume data storage.

The commonly used terms which we used in spring data mongodb are:

 

1. Database: It is container of collections like in RDBMS contains so many tables in it.

2. Collection: It is equivalent to tables in relational database(mysql).

3. Document: It is equivalent to rows in RDBMS. It is single record in collection.

4. Fields: It is equivalent to columns in RDBMS having a key value pair

 

Tools and technologies used

 

1. Firstly install mongodb in your local system according to OS.

2. JDK 8

3. Intellij

4. Maven is need to be installed in your system.

5. Postman which is need to hit the rest api.

 

 

There are two approaches through which we connect springboot java to MongoDB database:

1. Mongo Repository

2. Mongo Template

 

We will used Mongo Repository for integration. MongoRepository provide us common functionalities and it is similar to JPA Repository. It is easy to use and implement than mongo template.

 

Lets get started, we will make use of Spring Initializr tool for quickly setting up the project. We will use just one dependency as shown below:

 

 <dependencies>  
     <dependency>  
         <groupId>org.springframework.data</groupId>  
         <artifactId>spring-data-mongodb</artifactId>  
         <version>1.7.2.RELEASE</version>  
     </dependency>  
 </dependencies>  

 

Now we will create a simple model class of Users Information. We have a simple model class

User.java

 

 @Document(collection = "user")  
 public class User {  
 @Id  
 private String userId;  
 private String name;  
 private String email;  
 private long rollno;  
 ## Constructors  
 ## Setters and getters  
 ## tostring  
 }  

 

@Document annotation is used for creating and representing the collection name..It is used for the same purpose with @Entity annotation in JPA.

@Id is used for mark fields as identity purpose. It is used like we represent primary key in jpa.

 

Create a interface which extends MongoRepository. This will give us access to all the CRUD operations. Now you can easily add and remove element from your Mongodb collection.

UserRepository.java

 

 @Repository  
 public interface UserRepository extends MongoRepository<User, String> {  
 Student findByRollNumber(long rollno);  
 Student findByEmail(String email);  
 }  

 

Now Setup a connection between mongo and springboot. To connect to the mongoDB database, go to the Resouces directory and edit or create application.properties file according to this given below:

 

 

 #server  
 server.port=8081  
 #mongodb  
 spring.data.mongodb.host=localhost  
 spring.data.mongodb.port=27017  
 spring.data.mongodb.database=test  

 

 

Now, we create the User service. It contains four methods which is used for save, update, getall ,getbyelement and delete the users.

 

 public interface UserService {  
 List<User> findAll();  
 Student findByEmail(String email);  
 void saveOrUpdateUser(User user);  
 void deleteUser(String id);  
 }  

 

Create a service layer class

 

 @Service  
 public class UserServiceImpl implements UserService {  
 @Autowired  
 private UserRepository userRepository;  
 @Override  
 public List<User> findAll() {  
 return userRepository.findAll();  
 }  
 @Override  
 public User findByEmail(String email) {  
 return userRepository.findByEmail(email);  
 }  
 @Override  
 public void saveOrUpdateUser(User user) {  
 userRepository.save(user);  
 }  
 @Override  
 public void deleteUser(String id) {  
 userRepository.deleteById(id);  
 }  
 }  

 

 

Finally, we can create the REST controller

 

 @RestController  
 @RequestMapping("/users")  
 public class UserController {  
 @Autowired  
 private UserService userService;  
 @GetMapping(value = "/")  
 public List<User> getAllUsers() {  
 return userService.findAll();  
 }  
 @GetMapping(value = "/byEmail/{email}")  
 public User getUserByEmail(@PathVariable("email") String email) {  
 return userService.findByEmail(email);  
 }  
 @PostMapping(value = "/save")  
 public ResponseEntity<?> saveOrUpdateUser(@RequestBody User user) {  
 userService.saveOrUpdateUser(user);  
 return new ResponseEntity("User added successfully", HttpStatus.OK);  
 }  

 

 

 

Expert Guide to Integrating Firebase with Springboot Rest API

Integrating Firebase with Springboot Rest API

 

 

With the capability of training and building custom models, Firebase is an effective mobile app development toolkit to deploy machine learning in mobile devices. In this article, we will use the Cloud Firestore and we will learn how to connect to Firebase Firestore Database and build a CRUD application using Firebase with Spring boot Rest API

 

We, at Oodles, as a high-performance Machine Learning Development Company, explore how businesses can use the Firebase database to build custom applications.


 

What is Firebase Database?

 

Firebase is a cloud-based document store that is suitable for developing real-time applications. Firebase is owned by Google and is only available on GCP (Google Cloud Platform). The Firebase Realtime Database is a cloud-hosted database. Cloud Firestore is a scalable, flexible DB for web, server, mobile development from Firebase, and Google Cloud Platform. Data is stored in firebase as JSON form and synchronized in realtime to every connected client. Firebase is popular with developers for its rich and complete set of features to create applications without backends and servers. Following Cloud Firestore's NoSQL data model, you store data in documents that contain fields mapping to values. One collection can contain many documents and there are many fields, types, and values contained in a single document. Documents support many different data types like simple strings, number, timestamps, array, map, geopoint, complex and nested objects.

 

Types of Firebase Database 

 

Firebase from Google offers two cloud-based-accessible database solutions that support realtime data syncing:

1. Cloud Firestore

 

Cloud Firestore is a flexible database for mobile and web apps. Cloud Firestore is richer, faster, and more scalable than the Realtime Database.

 

2. Realtime Database

 

Realtime Database is the Firebase's first and original database. Mobile apps requiring synced states across clients in realtime, in this case, it is an efficient and low-latency solution.

 

Steps to integrate Firebase with Spring-boot Rest API

 

1. Go to https://console.firebase.google.com and sign up for an account.

2. Click the Add Project button

3. Type database name in the field.

4. Click the Create project button and click continue.

5. Now we have created a project on Firebase.

6. Then go to the cloud Firestore and click data.

7. Now you have to create a collection in which you can store documents.

8. In the collection, you can add JSON documents, delete documents, and delete fields also.

9. Once created the collection, we will go to project settings -> service Accounts tab to generate the key, download, and save it in your spring boot project, that we will use to connect to the firebase Firestore database.

10. Then go to https://start.spring.io/ and create a maven project, Once the project created then open the pom.xml file and add the below dependency.

 

 <dependency>  
 <groupId>com.google.firebase</groupId>  
 <artifactId>firebase-admin</artifactId>  
 <version>6.11.0</version>  
 </dependency>  

 

11. Add a service class named FirebaseInitialize which we will use to make a connection to firebase during the application startup. The class looks like this.

 

 @Service  
 public class FBInitialize {  
 @PostConstruct  
 public void initialize() {  
 try {  
 FileInputStream serviceAccount =  
 new FileInputStream("./serviceaccount.json");  
 FirebaseOptions options = new FirebaseOptions.Builder()  
 .setCredentials(GoogleCredentials.fromStream(serviceAccount))  
 .setDatabaseUrl("https://chatapp-e6e15.firebaseio.com")  
 .build();  
 FirebaseApp.initializeApp(options);  
 } catch (Exception e) {  
 e.printStackTrace();  
 }}}  

 

@Service and @PostConstruct these are the two annotations from Spring Boot.

The first line reads the serviceAccount.json which we generated on the firebase project settings.

It connects to firebase with FirebaseApp.initializeApp using the firebaseoptions builder class in which will have credentials that we extracted from serviceAccount.json and the database URL.

 

Now firebase connection is initialized, so let's perform crud operations.

 

1. Create a POJO class


 

 public class Patient {  
 private String name;  
 private int age;  
 private String city;  
       # setters and getters  
 }  

 

2. Create Service class

 

 @Service  
 public class PatientService {  
 public static final String COL_NAME="users";  
 public String savePatientDetails(Patient patient) throws InterruptedException, ExecutionException {  
 Firestore dbFirestore = FirestoreClient.getFirestore();  
 ApiFuture<WriteResult> collectionsApiFuture = dbFirestore.collection(COL_NAME).document(patient.getName()).set(patient);  
 return collectionsApiFuture.get().getUpdateTime().toString();  
 }  
 public Patient getPatientDetails(String name) throws InterruptedException, ExecutionException {  
 Firestore dbFirestore = FirestoreClient.getFirestore();  
 DocumentReference documentReference = dbFirestore.collection(COL_NAME).document(name);  
 ApiFuture<DocumentSnapshot> future = documentReference.get();  
 DocumentSnapshot document = future.get();  
 Patient patient = null;  
 if(document.exists()) {  
 patient = document.toObject(Patient.class);  
 return patient;  
 }else {  
 return null;  
 }  
 }  
 public String updatePatientDetails(Patient person) throws InterruptedException, ExecutionException {  
 Firestore dbFirestore = FirestoreClient.getFirestore();  
 ApiFuture<WriteResult> collectionsApiFuture = dbFirestore.collection(COL_NAME).document(person.getName()).set(person);  
 return collectionsApiFuture.get().getUpdateTime().toString();  
 }  
 public String deletePatient(String name) {  
 Firestore dbFirestore = FirestoreClient.getFirestore();  
 ApiFuture<WriteResult> writeResult = dbFirestore.collection(COL_NAME).document(name).delete();  
 return "Document with Patient ID "+name+" has been deleted";  
 }}  

 

3. Create a Rest controller

 

 @RestController  
 public class PatientController {  
 @Autowired  
 PatientService patientService;  
 @GetMapping("/getPatientDetails")  
 public Patient getPatient(@RequestParam String name ) throws InterruptedException, ExecutionException{  
 return patientService.getPatientDetails(name);  
 }  
 @PostMapping("/createPatient")  
 public String createPatient(@RequestBody Patient patient ) throws InterruptedException, ExecutionException {  
 return patientService.savePatientDetails(patient);  
 }  
 @PutMapping("/updatePatient")  
 public String updatePatient(@RequestBody Patient patient ) throws InterruptedException, ExecutionException {  
 return patientService.updatePatientDetails(patient);  
 }  
 @DeleteMapping("/deletePatient")  
 public String deletePatient(@RequestParam String name){  
 return patientService.deletePatient(name);  
 }  
 }  

 

The Oodles AI team has hands-on experience with advanced tools like Firebase, TensorFlow, Tesseract OCR, and more to build enterprise-grade AI solutions. 

Connect with our AI development team to know more about our artificial intelligence services.

Run Selenium With Headless Mode

Run selenium with headless mode

 

Selenium Web driver is a web automation tool which is used to run the test in various browsers such as Google Chrome, Firefox and Internet Explorer. Every browser needs a corresponding driver with selenium. By the help of these drivers at the time of test case is running, selenium automatically open the browser and executes test steps. You can easily see the browser and executed test actions on the screen.

 

Introduction to headless browser and headless testing

 

Headless browser is a web browser without GUI(graphical user interface). When we run the selenium test it behaves like a browser but not shown any GUI. In other words, when we run the selenium test case the browser is not shown on the screen, but it can run on background process and this process is called headless testing.

Today we mainly use Google chrome and Firefox for headless testing.

Before Google Chrome, headless execution testing was done by third-party browsers like PhantomJS, SlimerJS, Ghost and HTMLUnit.

 

In this article we do headless execution testing by Google Chrome using ChromeOptions and Xvfb.

 

1. Using ChromeOptions

For every chrome version there is a corresponding driver available. So firstly download the driver for respective operating system.

Google recently introduced a headless option for Chrome. It is available from version 59. If you want headless execution, so you need google chrome version 59 or above. It is very simple method if you want to done headless testing.The main advantage of this method of headless testing is it can run on all three OS platform(linux, windows and mac). It can saves so much time and increase peformance and speed in testing. Also you dont need to install browsers on servers.

ChromeOptions is class in selenium from which we set the arguements for headless execution.

For example:

 public class ChromeHeadlessTest {   
 @Test  
   public void testExecution() throws IOException {  
     System.setProperty("webdriver.chrome.driver", "<chromedriver_path of your local system>");  
     ChromeOptions options = new ChromeOptions();  
     options.addArguments("headless");  
     options.addArguments("window-size=1200x600");  
     WebDriver driver = new ChromeDriver(options);  
     driver.get("http://seleniumhq.org");  
     assertTrue(driver.findElement(By.id("q")).isDisplayed());  
     driver.quit();  
   }  
 }  


 

2. Using Xvfb( short for X virtual framebuffer)

 

We can also do headless execution testing using Xvfb in linux based systems(ubuntu, redhat and centos).

Xvfb or X virtual frame buffer is X11 server which does graphical operation in memory or in other words we say it is an in-memory display server specially for Unix distributed systems like linux. Using xvfb you can run graphical applications without display. Also it can have capability to take screenshots where htmlunit driver can’t take it.

Steps to setup Xvfb in your local system:


1.First we need to install xvfb using this command

sudo apt-get install Xvfb firefox

 

2. Then Start xvfb server by using this command
Xvfb :1 -screen 0 1024x768x24 &

The server will listen for connections as server number 1, and screen 0 will be depth 24 1024x768.

 

3. Then run the selenium test case, when you run this code it saves the screenshot image into directory and prints the title name of given URL.


 

 public class ChromeHeadlessTest1{  
 public static void main(String[] args) throws IOException {  
 ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()  
     .usingDriverExecutable(new File("/home/tarun/Downloads/chromedriver"))  
     .usingAnyFreePort().withEnvironment(ImmutableMap.of("DISPLAY", ":1")).build();  
 chromeDriverService.start();  
 WebDriver driver = new ChromeDriver(chromeDriverService);  
 driver.get("https://demoqa.com/buttons");  
 driver.manage().window().maximize();  
 JavascriptExecutor js = (JavascriptExecutor) driver;  
 TakesScreenshot scrShot = ((TakesScreenshot) driver);  
 File SrcFile = scrShot.getScreenshotAs(OutputType.FILE);  
 String fileWithPath = "./src/main/resources/s.png";  
 File DestFile = new File(fileWithPath);  
 Files.copy(SrcFile.toPath(), DestFile.toPath(), StandardCopyOption.REPLACE_EXISTING);  
 System.out.println("Screenshot taken");  
 System.out.println("Title is " + driver.getTitle());  
 }}  


 

Mapping the Advantages and Disadvantages of Sikuli for OCR

Advantages and Disadvantages of Sikuli for OCR

 

Sikuli is a tool to automate graphical user interfaces(GUI). You can automate anything using this GUI automation tool. It uses the Image recognition technique to interact with elements of any webpage or any window based popups(application). It considers all elements of window popups or webpage as images and recognizes these elements based on images. We, at Oodles, as an artificial intelligence development company are constantly adding new automation tools and techniques to our competency bucket. In this article, we explore the advantages and disadvantages of Siklui with regard to its text recognition capabilities. 

 

 

What is Sikuli?

 

Sikuli Automates anything whatever we see on the screen using the image recognition technology to identify and control elements. Sikuli uses the visual Image match method, in this method all elements of the webpage are taken as images and store inside the project resources directory. Sikuli will perform GUI interactions based on the image visual match, the image we passed as a parameter in all methods of Sikuli. (methods such as find, click, double-click region, etc.)

 

As we know, we selenium for automating web applications and it cant automate window desktop applications. Using Sikuli with selenium we can easily automate both desktop windows and web applications. Uploading and downloading is very easy in sikuli. We can also automate flash objects easily. Sikuli is preferred when GUI elements are stable(when GUI components not change).

 

By using sikuli, we can Automate adobe flash players both audio/video and flash games on the website. Also, Sikuli’s architecture consists of the OpenCV library that works for machine learning development models and applications. 

 

Sikuli working with text and OCR features

 

SikuliX uses the Tess4j library of java, which allows us to use the Tesseract-OCR features in java. In other words, internally, it uses Tesseract for OCR.

Sikuli version 2x provides TextOCR (Python scripts) and Text Recognizer (Java API level) methods.

 

We can easily integrate sikuli with java maven project.You can use below dependencies structure in pom.xml:

 

<dependency>

<groupId>com.sikulix</groupId>

<artifactId>sikulixapi</artifactId>

<version>1.1.2</version>

</dependency>

 

Advantages of sikuli

 

1. Open-source tool

2. We can automate desktop applications using sikuli.

3. It can easily automate Flash objects/flash websites.

4. When you test a web page, you don’t know the id/name of the element, then sikuli is useful. It can check the appearance of image and check the match is found or not.

5. It provides very simple API, sikuli methods are very easy to use.

6. Easily Integrated with selenium and other tools.

7. It can be used on any platform such as Windows/Linux/Mac/Mobile.

8. It allows us to automate anything we see on the screen.

 

Disadvantages of sikuli

 

1. We cannot assure you that the image match will be always accurate. Sometimes, if two or more similar images are available on the screen, Sikuli will attempt to select the wrong image.

2. If anyone of the image is missing in our directory, it will affect the execution of the program.

3. We have to take too many screenshots manually from the website we will going to automate.

4. “Find Failed ” exception will occur, if image appearance varies in pixel size.

Complete Guide to Deploying Facial Recognition Using OpenCV

 

Artificial intelligence (AI) is propelling a digital, technology-led future for humankind. The rapidly increasing pace of AI adoption is enabling businesses to enhance customer services and optimize backend operations with significant value. Facial recognition is one of the most widely adopted AI development services that is transforming the way businesses interact with customers. From employee attendance to contactless temperature scanner, facial recognition technology is making strides in the post-COVID world. In this article, we will go through a step-by-step guide to deploying facial recognition using OpenCV library. 

 

Employing Computer Vision and OpenCV for Facial Recognition

 

In this article, you are going to learn how to perform face recognition through webcam. This project is done by using the computer vision library OpenCV. This library was discovered for supporting real-time computer vision services and applications.

 

To create a simple face detection and recognition application we have three phases:

 

  1. Preparing Face Datasets

 

Data gathering is the main problem to build a face recognition application. It is difficult to collect a sample of one person manually. But if you have a limited dataset, then some different techniques we can use in this application for recognition are as follows:

 

1. Image Augmentation (create many images by one image)

2. One-shot learning (required only one image per person)

 

Below we demonstrate how datasets should be prepare per person:

 -datasets

   -alan_grant [22 images]

   -claire_dearing [53 images]

   -ellie_sattler [31 images]

   -ian_malcolm [41 images]

   -john_hammond [36 images]

   -owen_grady [35 images]

 

  1. Face Detection

 

An important phase of this application is face detection. The most common way to detect a face (or any objects), is using the Haar cascade classifier. It is the most effective object detection method, but you to trained it with a lot of images. Then Opencv comes with is detector and trainer feature, in this, you can train your own classifier for any object. If you don’t want to use your own classifier, then you can use a pre-trained classifier for face detection.

 

There are some other face detectors such as MTCNN, yoloface, and ultra-light face detector.

I found that yoloface is most efficient and has the highest accuracy.

 

  1. Model Traning and Facial Recognition

 

After detecting the faces, the next phase is recognition. Under facial recognition, we have several frameworks, such as Openface, Facenet, VGGface2, and MobileNetV2, etc.

 

There are some steps for face recognition:

1. Data preprocessing

2. Facial feature extraction

3. Comparison of features between the target face and faces from datasets.

 

In data preprocessing, we can crop and resize face images and captured inside boxes. OpenCV library is used in this process.

Below the image shows how a face is detected, resized, and cropped.

 

Image Credits: www.luxand.com/facecrop

 

Now calculate the face embeddings to get facial features from the processed face images.

We will begin by loading the TensorFlow model. Next, we will define the network input, get the embeddings, and save to a pickle file and load our embedding dataset with corresponding labels. Then use Euclidean distance and a threshold to determine who each detected face belongs to.

 

Image Credits: www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-learning/

 

Here are some required libraries used in this application:

1. Tensorflow

2. OpenCV

3. dlib

4. Keras

 

 

Deploying Facial Recognition Using OpenCV With Oodles

 

As we welcome a new normal, artificial intelligence and its underlying technology are becoming a ubiquitous part of our everyday life. We, at Oodles, ensure that businesses and their customers receive optimum solutions with AI-led innovation, such as facial recognition. 

 

Amid COVID-19 fears, facial recognition using OpenCV is emerging as an effective solution for enforcement of precautionary measures at shopping centers, corporate offices, and other public spaces.

 

The Oodles AI development team is constantly making efforts to build and deploy dynamic facial recognition systems, such as-

 

  1. Facial detection for employee attendance at offices
  2. Contactless temperature scanner
  3. Video analytics for CCTV cameras
  4. Insight generation from a large database such as tally, gender, and age.
  5. Integration of facial recognition and object detection with drones for remote monitoring, and more. 

 

Connect with our AI experts to know more about our AI and machine learning services.

 

Deploying Handwritten Text Recognition Using Tensorflow and CNN

 

Tensorflow is an open-source platform for machine learning. It is a deep learning framework, we use TensorFlow to build OCR systems for handwritten text, object detection, and number plate recognition. This solves accuracy issues. As a well-positioned AI development company, Oodles AI explores how to build and deploy handwritten text recognition using TensorFlow and CNN from scratch. 

 

Handwritten Text Recognition (HTR) systems power computers to receive and interpret handwritten input from sources such as scanned images. The systems are able to convert handwritten texts into digital text or simply can digitize, store, and extract valuable information for accurate analysis. At Oodles, we use tools like OpenCV and provide TensorFlow development services to build a Neural Network (NN) which is trained on line-images from the off-line HTR dataset.

 

This Neural Network (NN) model split the text written in the scanned image into segmented line images. These line-images are smaller than images of the complete page image. 9/10 of the words of a segmented line from the validation-set are correctly recognized and the character error rate is around 8%.

 

 Image Source:  https://medium.com/apache-mxnet/handwriting-ocr-line-segmentation-with-gluon-7af419f3a3d8

 

The network is made up of 5 CNN and 2 RNN layers and workflow can be divided into 3 steps-

 

1. Create 5 Convolutional Neural Network (CNN ) layers

There are 5 CNN layers. First, the Convolutional layer with 5×5 filter kernels in the first 2 layers Second, the non-linear RELU function is there. Finally, a pooling layer. The output is a feature map.

2. Create a Recurrent neural network (RNN) layers and return its output

Create and stack two RNN layers with 256 units each and a bidirectional RNN from the stacked layers. Get 2 output sequences forward and backward of size 32×256. The output Calculates loss value and also decodes into the final text.


 

Architecture

 

 

 

Image Source: https://medium.com/@arthurflor23/handwritten-text-recognition-using-tensorflow-2-0-f4352b7afe16 

 

3. Create IAM-compatible dataset and train model

The data-loader expects the IAM dataset [5] in the data/ directory. Below are the steps to get dataset:

  1. Register for free at this http://www.fki.inf.unibe.ch/databases/iam-handwriting-database;
  2. Download words/words.tgz and extract
  3. Download ascii/words.txt.
  4. Put words.txt into the data/ directory.
  5. Create the directory data/words/.
  6. Input the content (directories a01, a02, ...) of words.tgz into data/words/.

 

Train the model from scratch

 

To train the model from scratch we go to the src/ directory of our project and execute this command on terminal python main.py --train. After training, validation is done on a validation set (the dataset is split into 95% of the samples used for training and 5% for validation as defined in the class DataLoader). Validation is done by executing the command python main.py –validate. Training on the CPU takes about 30 hours on a normal configuration system.

 

Further Improvements to improve accuracy

Here are some steps to improve accuracy :

  • Add more CNN layers
  • Text correction(Autocorrect spell checker)
  • Increase input size
  • Better Decoding approach to improve accuracy: Use word beam search decoding 
  • Data augmentation: Magnify dataset-size by implementing further (random) transformations to the input images.
  • Remove cursive writing style

 

Requirements

 

  1. Tensorflow 1.8.0
  2. Flask
  3. Numpy
  4. OpenCV 3
  5. Spell Checker Autocorrect

 

Build Handwritten Text Recognition models using TensorFlow With Oodles AI

 

We, at Oodles, have hands-on experience in building and deploying printed and handwritten text recognition using TensorFlow, CNN, OpenCV, and Tesseract frameworks. Our team recently built an AI-powered OCR system to extract critical identity information form Aadhar cards, PAN cards, and other identity documents. The model enables digital businesses to streamline and automate onboarding and identity verification processes with ease and accuracy. 

 

Reach out to our AI development team to learn more about our AI OCR capabilities and projects. 

 

Understanding OCR and Ways to Improve OCR Accuracy

 

Artificial intelligence is reinventing traditional data and image processing capabilities for businesses to extract valuable insights. As an experiential provider of AI development services, Oodles AI discusses the fundamentals of traditional Optical Character Recognition systems and how AI tools and applications are improving OCR accuracy

 

What is OCR?

OCR stands for Optical Character Recognition. An OCR engine is the software that is used to extract text from scanned images of physical documents. There are multiple open-source engines used to perform OCR such as Cloud vision and tesseract. Tesseract is the most accurate and most commonly used open-source OCR engine. 

Emerging providers of OCR systems are proactively using AI technologies such as computer vision services to optimize data extractions tasks. We, at Oodles, harness computer vision and natural language processing technologies to build dynamic OR systems for identity verification and healthcare services.  

 

 

 

 

Most OCR engine provides 96% - 98% accuracy at the page level. That means in a page of 100 words 96 – 98 words are accurate. OCR accuracy is measure by taking the output text of OCR results of an image and comparing it to the original image text. Sometimes OCR provides poor results because of the image quality is bad or image resolution is low

 

Here are the main points to improve OCR accuracy by processing your image-

 

Get perspective transform of an image

Using get perspective and warp perspective in Opencv library and python, we can easily change the geometric transformation of an image by detecting its edges using a canny edge detection feature. Here the transformation image is shown below-

 

 

 

Image quality and format is good( prefer tiff and png format)

If the image source quality is good then we get good OCR output. We take care of that the image is not hazy, it is important to use the cleanest image source. Accuracy also depends on image format if the image format is jpeg then sometimes it gives poor results. But if the image format is png or tiff or jpg than it improves OCR accuracy.

 

Cropping of an image

When we try to deploy OCR systems for an image that contains text in some area, then cropping is required. We crop only that part of the image which contains text, it increases the OCR accuracy of extracted data in compare of without cropped image.

 

Binarizing the Image

Binarization is used to convert colored images (RGB) to a black and white image. Use features of OpenCV library like Adaptive Thresholding, we can convert image to white and black. Most Ocr engine uses binarization internally. Here we see the binarization of an image-

 

 

 

Increase Contrast and Sharpness of the image

Increase the contrast and density of the image before practicing OCR. By increasing the contrast between the text/image and its background, it gives out more accuracy in the output. If the Sharpness of an image is good it gives more clarity in the text.

 

Increase Scanning Resolution

The Standard size of the image is scaled to at least 300 (DPI) Dots Per Inch. DPI lower than 200 will give unclear results while keeping the DPI above 600 will increase the size of the output file without much quality.

 

Rotate pages to the correct orientation(Deskew)

An image that is not straight is called a skewed image. De-skewing the image means to bring an image to correct orientation by rotating it. If the image is skewed to any side we have to do the following steps:

1. Detect the text block of  image.

2. Calculate the angle of rotation.

3. Rotate the image to correct skew.

Below is a demonstration of a deskewed image on the right side

 

 

 

Open-source Tools and Libraries for Image Processing

  • Leptonica
  • Tensorflow
  • OpenCV
  • Awt graphics2d

 

JWT Authentication for Security

In this article, we will take a look at what JSON Web Token(JWT) Authentication security and all about

We will start with basic defination of JWT & how it works, and finally create a simple Spring boot application that will take some data from database and insert it into a JWT.

 

What is JWT & its need?

 

A JSON Web Token (JWT) is a compact and secure , and self-contained way of securily transmitting information between multiple orgainization in the form of a JSON object.

Say when you login to an app, like say Instagram. Instagram allows users to log in using their Facebook profile. So when the user wants to log in Facebook, the Instagram contacts Facebook’s Authentication server with his credentials like username and password.

Once the Authentication server verifies the user credentials, it will create a json web token and send to the user. The app now get token and allow the user to access its data.
 

JWT Structure

Json web token Structure is divided into three parts-

1. Header

2. Payload

3. Signature

1. Header consist of two parts:

1. Token type 2.Hashing algorithm

Example-

           {
           "alg": "HS256",
           "typ": "JWT"
           }

2. Payload is where the actual information is stored.

Example-

          {
          "sub": "65165751325",
          "name": "Rahul",
          "admin": true
          }

3. Signature: To create a Singnature part we have to take encoded header, encoded payload,a secret key, and the algorithm of header

Example-

         HS256(

                Encode(header),

                Encode(payload),

                secret)

To easily verify,decode, generate, or others advance features of JWTs, go to JWT.IO Debugger by Auth0.

 

JWT Working flow


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Now that we understand only what is JSON and how its look like , lets take a example how to build a simple Spring boot application using JWT authentication for securing our exposed Restful Api.

 

Creating the Project

To generate the project we uses Spring Initializr web tool.

1. Go to http://start.spring.io

2. Enter Artifact as “demo”

3. Change Package Name to “com.example.jwtsecurity

4. Select JPA, WEB, MYSQL, Spring-Security, java-JWT dependencies.

5. Click Generate Project to download the project.


 

Define the Application properties as follows-

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/databasename
spring.datasource.username = root
spring.datasource.password = root
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

 

Create the entity class as follows-:

package com.demo.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
@Entity
@Table(name = "user")
public class DAOUser {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private long id;
        private String username;
        @JsonIgnore
        private String password;
// default Constructor
// Constructor using fields
// getter and setters

Define the UserDTO model class as follows. This class is responsible for getting data from user and passing it to the DAO layer.

package com.demo.model;
public class UserDTO {
        private String username;
        private String password;
//getter and setters
//Constructors

we define the UserDao which is an interface extends Crud Repository

@Repository
public interface UserDao extends CrudRepository<DAOUser, Integer> {
}

Expose a POST API /authenticate using the JwtAuthenticationController. This POST API gets the username and password of the user in the Postman body. By the help of Spring Authentication Manager, we authenticate the username and password. If the username and password are valid and match to the database data , then a JWT token is created and provided to the client.

@PostMapping("/authenticate")
public String generateToken(@RequestBody LoginDto logindto) throws Exception {
    try {
        authenticationManager.authenticate(
                new UsernamePasswordAuthenticationToken(logindto.getUsername(), logindto.getPassword())
        );
    } catch (Exception ex) {
        throw new Exception("inavalid username/password");
    }
    return jwtTokenUtil.generateToken(logindto.getUsername());
}

 

JWT Filter

This class extends the Spring Web Filter OncePerRequestFilter class. For any incoming request, this class gets first executed. It checks if the request has a valid JWT token, then it sets the authentication in context to specify that the current user is authenticated.

JWT AuthenticationEntryPoint

It extends Spring's AuthenticationEntryPoint class and override its commence method. It sends error code 401 for every unauthenticated request.

WebSecurityConfig

WebSecurityConfig is a convenience class that allows customization to both HttpSecurity and WebSecurity. This securityconfig class extends the WebSecurityConfigurerAdapter.

JWT Util

The JwtTokenUtil is used for performing JWT operations like creation and validation. Validations include the time in which token is expires. For achieving this., it makes use of the io.jsonwebtoken.Jwts.

public String generateToken(String username) {
        Map<String, Object> claims = new HashMap<>();
        return createToken(claims, username);
    }
    private String createToken(Map<String, Object> claims, String subject) {
        return Jwts.builder().setClaims(claims).setSubject(subject).setIssuedAt(new Date(System.currentTimeMillis()))
          .setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * 2))
                .signWith(SignatureAlgorithm.HS256, secret).compact();
    }
    public Boolean validateToken(String token, UserDetails userDetails) {
        final String username = extractUsername(token);
        return (username.equals(userDetails.getUsername()) && !isTokenExpired(token));
    }

 

Then run the spring boot Application

Open the POSTMAN app and send a post request with the JSON object ie username and password in its body. If the username and password information are present in the database than it return the token if not present then it gives error.

As shown below the result will be a JSON Web Token:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If you copy the given token into the JWT.IO Debugger, you will see that the username and password is same, but with a few extra things(header,payload & signature).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Validate the JSON Web Token

Using the above-generated token in the header and try accessing the URL localhost:8080/hello as follows:

 


 

 

 

 

 

 

 

 

 

 

 

 

 

Conclusion

Contrasted with other web tokens like Simple Web Tokens (SWTs) or Security Assertion Markup Language (SAML), JWT is a lot less complex as it depends on JSON which is more obvious than XML.
On the off chance that we encode the JSON, it will turn out to be much more littler in size than SAML, making it simpler to go in HTML and HTTP situations.

Talking from a use perspective, JWTs are utilized at Internet scale. This implies it is simpler to process on the client's gadgets, be it PCs or portable.

Aside from authenctication, JSON Web Token are an extraordinary and make sure about method for transmitting information between different gatherings. The way that JWTs have marks makes it simpler for everybody to effectively recognize the sender of data. All you need is the right key.

I trust this post helped you see how to execute a straightforward JSON Web Token Authentication in your application. Don't hesitate to remark and ask/recommend anything! I'd be glad to talk ?

Banner

Don't just hire talent,
But build your dream team

Our experience in providing the best talents in accordance with diverse industry demands sets us apart from the rest. Hire a dedicated team of experts to build & scale your project, achieve delivery excellence, and maximize your returns. Rest assured, we will help you start and launch your project, your way – with full trust and transparency!