Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How Does Contour Extraction Work?

I've been modifying squares.py to be able to detect contours of 3D objects. My goal is for it to extract the shapes of 3D objects (i.e. get the squares of a cube). However, whenever I run my code on the image below, drawing the contours gives me a hexagon and a green Y. Is there any way to modify this so that for each contour, I get the polygon of a square/ shape? Thanks!

image description

image description

How Does Contour Extraction Work?

I've been modifying squares.py to be able to detect contours of 3D objects. My goal is for it to extract the shapes of 3D objects (i.e. get the squares of a cube). However, whenever I run my code on the image below, drawing the contours gives me a hexagon and a green Y. Is there any way to modify this so that for each contour, I get the polygon of a square/ shape? Thanks!

image description

image description

!/usr/bin/env python

'''

Usage:
ObjectDescriptors.py [<image source="">]

Converts visual objects into basic shapes.

'''

import cv2
import numpy as np

relative module

import video

built-in module

import sys

from bulbs.neo4jserver import Graph

def findShapes(img): img = cv2.GaussianBlur(img, (1, 1), 0) cv2.imshow("test", img) shapeList = []

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = cv2.bilateralFilter(gray, 11, 17, 17)
edged = cv2.Canny(gray, 0, 200)
cv2.imshow("test", edged)
contours, hierarchy = cv2.findContours(edged, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
    cnt_len = cv2.arcLength(cnt, True)
    cnt = cv2.approxPolyDP(cnt, 0.01*cnt_len, True)
    shapeList.append(cnt)
keyVertices = []
for i in shapeList:
    print("Shape Coordinates:",  [pts for pts in i])
return shapeList

def removeDuplicates(contours): print(2)

if __name__ == '__main__': from glob import glob for fn in glob('../data/perfectcube/png'): img = cv2.imread(fn) squares = findShapes(img) cv2.drawContours( img, squares, 0, (0, 255, 0), 3 ) cv2.drawContours( img, squares, 1, (255, 0, 0), 3 ) cv2.drawContours( img, squares, 2, (0, 0, 255), 3 ) cv2.imshow('squares', img) ch = 0xFF & cv2.waitKey() if ch == 27: break cv2.destroyAllWindows()

How Does Contour Extraction Work?

I've been modifying squares.py to be able to detect contours of 3D objects. My goal is for it to extract the shapes of 3D objects (i.e. get the squares of a cube). However, whenever I run my code on the image below, drawing the contours gives me a hexagon and a green Y. Is there any way to modify this so that for each contour, I get the polygon of a square/ shape? Thanks!

image description

image description

!/usr/bin/env python

'''

Usage:
ObjectDescriptors.py [<image source="">]

Converts visual objects into basic shapes.

'''

import cv2
import numpy as np

relative module

import video

built-in module

import sys

from bulbs.neo4jserver import Graph

def findShapes(img):
    img = cv2.GaussianBlur(img, (1, 1), 0)
    cv2.imshow("test", img)
    shapeList = []

[]

    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
 gray = cv2.bilateralFilter(gray, 11, 17, 17)
 edged = cv2.Canny(gray, 0, 200)
 cv2.imshow("test", edged)
 contours, hierarchy = cv2.findContours(edged, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
 for cnt in contours:
     cnt_len = cv2.arcLength(cnt, True)
     cnt = cv2.approxPolyDP(cnt, 0.01*cnt_len, True)
     shapeList.append(cnt)
 keyVertices = []
 for i in shapeList:
     print("Shape Coordinates:",  [pts for pts in i])
 return shapeList

shapeList def removeDuplicates(contours): print(2)

print(2) if __name__ == '__main__': from glob import glob for fn in glob('../data/perfectcube/png'): img = cv2.imread(fn) squares = findShapes(img) cv2.drawContours( img, squares, 0, (0, 255, 0), 3 ) cv2.drawContours( img, squares, 1, (255, 0, 0), 3 ) cv2.drawContours( img, squares, 2, (0, 0, 255), 3 ) cv2.imshow('squares', img) ch = 0xFF & cv2.waitKey() if ch == 27: break cv2.destroyAllWindows()

cv2.destroyAllWindows()
click to hide/show revision 4
No.4 Revision

How Does Contour Extraction Work?

I've been modifying squares.py to be able to detect contours of 3D objects. My goal is for it to extract the shapes of 3D objects (i.e. get the squares of a cube). However, whenever I run my code on the image below, drawing the contours gives me a hexagon and a green Y. Is there any way to modify this so that for each contour, I get the polygon of a square/ shape? Thanks!

image description

image description

!/usr/bin/env python

#!/usr/bin/env python                                 

'''                                                   

Usage:
ObjectDescriptors.py [<image source="">]

source>] Converts visual objects into basic shapes.

'''

shapes. ''' import cv2
import numpy as np

# relative module

module import video

# built-in module

module import sys

from sys #from bulbs.neo4jserver import Graph

Graph
def findShapes(img):
    img = cv2.GaussianBlur(img, (1, 1), 0)
    cv2.imshow("test", img)
    shapeList = []

    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    gray = cv2.bilateralFilter(gray, 11, 17, 17)
    edged = cv2.Canny(gray, 0, 200)
    cv2.imshow("test", edged)
    contours, hierarchy = cv2.findContours(edged, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    for cnt in contours:
        cnt_len = cv2.arcLength(cnt, True)
        cnt = cv2.approxPolyDP(cnt, 0.01*cnt_len, True)
        shapeList.append(cnt)
    keyVertices = []
    for i in shapeList:
        print("Shape Coordinates:",  [pts for pts in i])
    return shapeList def removeDuplicates(contours):
    print(2)

print(2)    

if __name__ == '__main__':
    from glob import glob
    for fn in glob('../data/perfectcube/png'):
        img = cv2.imread(fn)
        squares = findShapes(img)
        cv2.drawContours( img, squares, 0, (0, 255, 0), 3 )
        cv2.drawContours( img, squares, 1, (255, 0, 0), 3 )
        cv2.drawContours( img, squares, 2, (0, 0, 255), 3 )
        cv2.imshow('squares', img)
        ch = 0xFF & cv2.waitKey()
        if ch == 27:
            break
    cv2.destroyAllWindows()