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

Functions that help to understand json(dict) structure
Scapy How converting hex to new packet
Write and read test files in dictionary format
Python 3.x Connect to account with request POST
AttributeError: module 'networkx' has no attribute 'Graph'
How to exclude selected domains from python crawl script in google search
Python - Py2exe error
Anaconda import packages from another environment
How to Drag & Drop Multiple rows of a QTableView in pyqt5
Handle prompts in Python - popen
How to create an infinite iterator to generate an incrementing alphabet pattern?
Python RTMP Authenticiation Script
How to change background colour in Kivy
Is it correct to use kwargs in the following scenario of python code?
List comprehension with elements appearing twice
How to unread a single char in Python?

Categories

HOME
rest
jsf
numpy
app-inventor
signalr
openssl
vhdl
ncurses
visual-studio-2013
google-tag-manager
angular2-routing
laravel-5.2
computer-vision
docker-swarm
command
ruby-on-rails-3
bibtex
codeeffects
automated-tests
console
iis-7.5
desktop
netflix-feign
deeplearning4j
constructor
pca
ipfs
jboss-eap-7
iso
gatsby
informatica-powercenter
ctypes
public-key-encryption
mongodb-query
gwtp
eclipse-luna
python-unicode
aptana
aws-cognito
sql-update
thingsboard
jquery-form-validator
ghost-inspector
tarantool
azure-servicebus-queues
spring-test
tflearn
jflex
badge
skmaps
unpack
vcard
partial-application
thinking-sphinx
bitcoin-testnet
entity-system
graph-databases
hawtio
web-audio-api
oscommerce
lexical-analysis
jupyter-console
facebook-chatbot
z3py
onmouseover
aqgridview
tableau-server
chrome-remote-desktop
etherpad
pagefile
fontconfig
static-code-analysis
polar-coordinates
project-template
sql-server-administration
picasa
activeweb
mailcatcher
gitweb
json-schema-validator
django-filer
linkageerror
metalsmith
asp.net-mvc-partialview
aerogear
throughput
direct3d12
intellitest
jericho-html-parser
anti-patterns
xaml-designer
pl-i
chaining
python-ggplot
inputaccessoryview
tilestache
activity-streams
gyroscope-framework
sortable
funq
sthttprequest
code-testing
swrl
windows-update
cgimageref
soa-suite
process-monitor
pys60
redirectstandardoutput
v4l
ubuntu-11.04
electronic-signature
galaxy-tab
msbuildextensionpack
server-error
.app
email-spec
trampolines
project-lifecycle
database-diagramming

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