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

Bokeh plot conditional background color
module installation - Mock
Best Way to create a bounding box for object detection
Read csv from Amazon s3 using python2.7
Could someone explain this Python import error? Anaconda 3.5
Python Tor server. stem/flask not showing images in tor
Python3 Socket / Selector register more than one event
iPython sent as background process when bash script executed as subprocess
Matplotlib xticks as days
Renaming tuple column name in dataframe
Jupyter Notebook Toggle Scrolling using Magic Command
Multiple linear regressions according to first column in pandas
Passing tensorflow placeholders as function parameters
Python(3.6)-How can I create a demo program that will create an object from the VotingMachine class I have created?
Python and Plotly offline: create (empty) graph and add traces with for-loop
Installing python on Mac not working

Categories

HOME
python
semantic-ui
vhdl
freepascal
mapping
performancecounter
backup
label
angular2-directives
transparent
bibtex
automated-tests
rocketmq
yocto
shader
currency
openwrt
metronic
hashicorp-vault
simple-injector
derived
google-api-java-client
thumbnails
pycrypto
jni
nmake
google-maps-android-api-2
dspic
remove-method
philips-hue
guile
classpath
ab-initio
google-api-dotnet-client
fileinfo
dhtmlx-scheduler
pep8-assembly
idl
shapes
ios-ui-automation
coreclr
silverlight-3.0
twiki
bayesian-networks
viewgroup
upsert
openweathermap
nsjsonserialization
recycle-bin
webdatagrid
android-bitmap
scd
fedora20
date-range
efxclipse
spring-ioc
firepath
gitweb
uiprogressview
pagekit
gherkin
contour
mercurial-hook
django-south
asynccallback
flexjson
magento-1.4
loopj
except
void
direct3d12
document-oriented-db
matcaffe
programming-paradigms
wif
scrollspy
httpie
hiera
jython-2.7
c++-actor-framework
orientation-changes
gmaps4rails
libsndfile
kendo-mvvm
joox
edit-in-place
lov
angulartics
sslexception
robospice
onselect
stagefright
entity-framework-4.1
appfog
awesomeprint
objcmongodb
cgpath
sequelpro
couchdb-lucene
javascriptserializer
symfony-2.0
datarepeater
icefaces-3
macruby
flash-cs5.5
serp
easygui
django-nose
requestfactory
carbide
revision
nt4
dirty-data
dotproject
cots

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App