python


grid detection in opencv python


I have an image that has items inside a grid. One stage of the problem is to detect and build a mask of the full grid, which can be slightly rotated clock or anticlockwise. My current CV pipeline extracts (probabilistic) Hough lines from an image and then uses its contours to filter for a set of rectangles (call the actual and the detected sets R' and R respectively). However due to occlusions and lighting conditions the hough lines (and consequently all downstream contours and lines segments) are incomplete (R << R'). Schematically the problem i must solve is to infer the missing grid components (R'- R) given the detected grid cells.
One strategy I am considering is the following. Foreach detected rectangle contour r in R do:
1- using fitLine() find vertical and horizontal lines that pass through the center of r (see code and image below)
rect = cv2.minAreaRect(r)
box = cv2.boxPoints(rect)
box = np.int0(box)
cx = np.int0(rect[0][0])
cy = np.int0(rect[0][1])
w = np.int0(rect[1][0])
h = np.int0(rect[1][1])
cv2.drawContours(img,[box],0,255,1)
[vx,vy,x,y] = cv2.fitLine(box, cv2.DIST_L2,0,0.01,0.01)
lefty = int((-x*vy/vx) + y)
righty = int(((cols-x)*vy/vx)+y)
start = (cols-1,righty)
end = (0,lefty)
cv2.line(img,start,end,255,1)
# HORIZONTAL
nx,ny = 1,-vx/vy
mag = np.sqrt((1+ny**2))
vx,vy = nx/mag,ny/mag
# Now find two extreme points on the line to draw line
lefty = int((-x*vy/vx) + y)
righty = int(((cols-x)*vy/vx)+y)
start = (cols-1,righty)
end = (0,lefty)
cv2.putText(img,'start',(start[0]-60,start[1]),font,0.5,255,1)
cv2.putText(img,'end',end,font,0.5,255,1)
cv2.line(img,start,end,255,1)
2- create a mask of same size and rotation as the source rectangle and move along the line define in (1), drawing the same shape rectangle as the source if there is no previously detected contour in the same area
ie.
My questions are:
is there a more efficient and better way to solve this problem?
What is best way to move the mask along the line that is at an angle
(given by cv2.minAreaRect)?
thank you


Related Links

need help about SVM in Python and Matlab
How can a portal user modify his own partner data in Odoo 8?
Name or service not known
how to append a row from one dataframe to a new dataframe
Theano: ifelse TypeError
Can generators be recursive?
Adding django action to installed app
Python running manage.py migrate wont work with MySQL db [duplicate]
Error on Python serial import
Db in openshift is shutdown every 30 minutes
KNN classifier not working in python on raspberrypi
pandas.DataFrame.loc , Labeling data in new column
Scikit learn GridSearchCV fit method ValueError Found array with 0 sample
Python Figure not responding after I ask for input?
Python BST not working
Convert Excel style date with pandas

Categories

HOME
sql-server-2008
paypal
json
converter
ember.js
plsql
semantic-ui
ocaml
backup
visualization
tomcat7
transparent
vlc
xtext
browserify
xcode8.3
deeplearning4j
google-classroom
metronic
jboss-eap-7
cartodb
ndis
automata
symfony2-easyadmin
glpk
typeahead
rapidjson
titan
riak-ts
android-toolbar
arraylist
google-openid
jpeg2000
boolean-expression
profile
restfb
delete-file
jquery-waypoints
scalajs-react
reply
aurelia-binding
pitest
devforce
red-black-tree
picturebox
read-write
ipfw
nsurlconnection
viewstate
fax
distributed-transactions
excel-interop
rich-text-editor
archer
number-theory
defold
livescribe
spell-checking
component-pascal
fedora20
redux-router
gmt
laravel-query-builder
sql-import-wizard
c64
glkit
activeweb
angularjs-ng-pattern
com-interop
multilingual-app-toolkit
fps
distribute
cmocka
direct3d12
ninject.web.mvc
rad
pyrocms
integral
risk-analysis
sparse-file
ibm-data-studio
mdm-zinc
android-search
java-melody
proximity
candidate-key
eclipse-classpath
dache
proxies
android-looper
unison
svcutil.exe
sim900
dig
entity-framework-4.1
mstsc
radchart
cadisplaylink
subtract
msgbox
mysql-error-1045
zookeeper
serp
curljs
executable-format
goliath
scalaxb
sitemappath
quick-search
jquery-ui-button
swfloader





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android


MS Developer
developer works
python
ios
c
html
jquery


RDBMS discuss