Ask Your Question
0

Convert Image to Occupancy Grid

asked 2018-03-15 22:04:40 -0600

Stephane gravatar image

updated 2018-03-15 22:48:06 -0600

I was wondering how I might turn a bird's eye view image of a map into an occupancy grid. I use an edge detection algorithm to detect obstacles in the bird's eye view image and would like to then translate this information into an occupancy grid (the black squares would be obstacles as detected by the edge detection algorithm, and the white squares would be free space).

The image I would like to convert:

https://imgur.com/a/6UL6g

I would like to turn the image above into something along the lines of this (the image below is just crudely hand drawn)

https://imgur.com/a/vPQNu

My code for edge detection:

import cv2
import numpy as np

roomimg = cv2.imread("/Users/2020shatgiskessell/Desktop/roomimage.jpg")
gray = cv2.cvtColor(roomimg, cv2.COLOR_BGR2GRAY)

gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,3,0,0.04)

dst = cv2.dilate(dst, None)

roomimg[dst>0.01*dst.max()]=[0,0,255]


cv2.imshow('dst',roomimg)
if cv2.waitKey(0) & 0xff == 27:
cv2.destroyAllWindows()
edit retag flag offensive close merge delete

Comments

maybe replace the 1st image with an "uncluttered" one ?

ppl can still draw their own harris dots if they want, using the code above

berak gravatar imageberak ( 2018-03-16 06:03:10 -0600 )edit

btw, above does corner detection, not edge detection (not the same thing !)

berak gravatar imageberak ( 2018-03-16 06:55:18 -0600 )edit

your scene is synthetic, your camera and lighting looks static. if you have an image of the "background", i.e. no obstacles, you can take the difference between that and the current view.

crackwitz gravatar imagecrackwitz ( 2018-03-17 14:52:47 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-03-16 06:54:10 -0600

berak gravatar image

updated 2018-03-16 07:07:54 -0600

your problem is basically known as "segmentation", and maybe you should look for higher level methods to achieve this.

as an example, opencv_contrib has a newly added hfs module, that does this easily:

image description

import cv2
import numpy as np

img = cv2.imread(image_path)

# create engine
engine = cv2.hfs.HfsSegment_create(img.shape[0], img.shape[1])
engine.setSlicSpixelSize(200);
# perform segmentation
# now "res" is a matrix of indices
# change the second parameter to "True" to get a rgb image for "res"
res = engine.performSegmentCpu(img, False)

i choose the color representation here, and ofc. it would look nicer w/o the harris dots you added.

there are also a couple more algorithms to try in ximgproc, and we have an fcn pretrained cnn for this, too !

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-03-15 22:04:40 -0600

Seen: 3,346 times

Last updated: Mar 16 '18