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

Django update model entry using form fails
ctypes using HRESULT(python)
How to export property values with django-import-export
Plotting Coordinate Lines Using Matplotlib
BASH - Summarising information present in 2 genotype data columns in one column (ped file) [closed]
Python 3: How to call function from another file and pass arguments to that function ?
Streaming mp3 files in Django through Nginx
Opening PE file with Bokken
Python exercise: last letter / first letter
Python/Pygame: Can you run a program whilst having a Pygame window that can still update?
Replacing values in array from netCDF
confused about Python list syntax
Object orientated function parameter to alter variables
Batch processing and breaking up an image
How can I connect multiple if statements when using regular expressions?
Using A For Loop to Return Unique Values in a Pandas Dataframe

Categories

HOME
laravel-5
cil
sass
boost-thread
jasmine
smartphone
survival-analysis
is-empty
phaser-framework
iis-7.5
vsftpd
contact-form-7
google-plus
iso
flann
cs-cart
dlib
simple-injector
ida
riak
mule-studio
scenebuilder
phpbb
alfresco-share
grub2
off-canvas-menu
jsonserializer
cruisecontrol.net
scalaz7
fop
hhvm
kitematic
logarithm
scalajs-react
samsung-mobile
auditing
opencart2.3
metis
chrome-native-messaging
cell-array
hibernate-cache
rowcount
oracle-xml-db
transient
node-horseman
large-data
service-locator
nunit-3.0
twiki
rule
mediawiki-extensions
react-native-router-flux
distributed-transactions
pytest-django
rkt
mod-fcgid
filepath
fqdn
ideone
appstore-approval
seamless-immutable
pinvoke
xmgrace
scd
qos
bettercms
autoresize
svn-merge
master
iostat
libreadline
push-diffusion
software-product-lines
django-filer
dbscan
remoteapp
dac
twgl.js
interactive-brokers
affix
lmfit
registrykey
viper-architecture
apache-mina
uptodate
named-ranges
ibmsbt
ember-addon
aquafold
planetary.js
mbox
visual-studio-addins
gamepad
modeshape
jqmobi
localtime
apache2.2
lame
soa-suite
process-monitor
wpdb
dynamic-data
dropdownlistfor
javascriptserializer
file-exists
visual-web-gui
objectbrowser
shared-objects
squeel
chatroom
recordset
front-controller
scatterview
inline-if
project-lifecycle

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