Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task done #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions ajit2704/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# PROBLEM STATEMENT

### Input

This image of a graph,having X and Y axes.

![alt tag](input.jpg)

### Desired Output

Input image + rectangular boxes drawn around the markings on the axes.

![alt tag](output.jpg)

### Languages

C++ / Python

### Useful tips

Browse through the OpenCV library documentation and find functions that would be helpful to implement this.

The basic idea of solution, is to find contours (regions, maybe `rectangular` ones) that have atleast a certain level of text density and are on the left side of Y-axis or below the X-axis.

Text can be recognised by the sudden change in intensity level with respect to the background.

But the trick lies in differentiating the X & Y axes from the graph's curve - use Google, StackOverflow and OpenCV tutorials to the maximum extent.

It may be tough to get all the readings accurately. but it's fine.

Good luck!

### Important Note

Coordinates of the origin of the graph should not be hard-coded specific to a particular image. It should work on any similar graph image with 2 perpendicular lines.

Variables like cutoff text density can be hard-coded, but it'd be better if the cutoff is dynamically decided.

### Submission Guidelines

(1) Fork this repository on GitHub.

(2) Clone your fork with `git clone` statement.

(3) Make your local changes, in a sub-directory (say, `graph-detect/<username>/`).

(4) Push these changes to your fork with `git add`, `git commit` and `git push` statements.

(5) Create a Pull Request to this repository by comparing across forks with your fork.
50 changes: 50 additions & 0 deletions ajit2704/auv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""


import numpy as np
import cv2

im = cv2.imread('input.jpg')
im3 = im.copy()

gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(5,5),0)
thresh = cv2.adaptiveThreshold(blur,255,1,1,11,2)



contours,hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

samples = np.empty((0,100))
responses = []
keys = [i for i in range(1,100)]

for cnt in contours:
if cv2.contourArea(cnt)>50:

[x,y,w,h] = cv2.boundingRect(cnt)

if h<11.05:
cv2.rectangle(im,(x,y),(x+w,y+h),(255,0,0),2)
roi = thresh[y:y+h,x:x+w]
roismall = cv2.resize(roi,(10,10))
cv2.imshow('auv',im)
key = cv2.waitKey(0)


if key in keys:
responses.append(int(chr(key)))
sample = roismall.reshape((1,100))
samples = np.append(samples,sample,0)

responses = np.array(responses,np.float32)
responses = responses.reshape((responses.size,1))
print ""

np.savetxt('generalsamples.data',samples)
np.savetxt('generalresponses.data',responses)
Binary file added ajit2704/input.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ajit2704/output.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions auv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""


import numpy as np
import cv2

im = cv2.imread('input.jpg')
im3 = im.copy()

gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(5,5),0)
thresh = cv2.adaptiveThreshold(blur,255,1,1,11,2)



image,contours,hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: need more than 2 values to unpack

Have a look at documentation of the findContours() function


samples = np.empty((0,100))
responses = []
keys = [i for i in range(1,100)]

for cnt in contours:
if cv2.contourArea(cnt)>50:

[x,y,w,h] = cv2.boundingRect(cnt)

if h<11.05:
cv2.rectangle(im,(x,y),(x+w,y+h),(255,0,0),2)
roi = thresh[y:y+h,x:x+w]
roismall = cv2.resize(roi,(10,10))
cv2.imshow('auv',im)
key = cv2.waitKey(0)


if key in keys:
responses.append(int(chr(key)))
sample = roismall.reshape((1,100))
samples = np.append(samples,sample,0)

responses = np.array(responses,np.float32)
responses = responses.reshape((responses.size,1))
print ""

np.savetxt('generalsamples.data',samples)
np.savetxt('generalresponses.data',responses)