Skip to content

PharrellG/-archi

 
 

Repository files navigation

archiCV

OpenCV work for Architecture, especially the Landscape Architecture, and we free the so-called LA planning or design workers, because only we free the architector then they can do the true thing not just be used as a tool to copy picture to cad or to just make a picture more beautiful but not to make the true design and plan.

more details on ArchiCV website: http://www.caup.cn

Get started

Install and start to use archicv.
$pip install archicv

Archicv is a python library, so it's recommended to use pip to install archicv.
Archicv is based on OpenCV and NumPy, so that required to install OpenCV and NumPy.
NumPy is easy to install, $pip install numpy is the best way.
If you use Mac OS system, we recommend much the use of HomeBrew to install opencv,
just one step, $brew install opencv.If you are using Ubuntu, you can use pip or apt-get to install opencv.
On mac, pip can't install opencv.
There are three ways to install archicv, $pip install archicv and $easy_install archicv, pip is more recommended. The third way is download the setup package of archicv from pypi, and install it manually.

 pip:

$pip install numpy
$brew install opencv

$pip install archicv

 easy_install:

$pip install numpy
$brew install opencv

$easy_install archicv

 manually install:

$pip install numpy
$brew install opencv
    
$tar -xf archicv archicv-0.0.1.18.32.tar.gz
$cd archicv-0.0.1.18.32
$python setup.py install

When successfully install the library,
we can have a test to write a little program to generate a ".jpg" file from a ".png" one.

 example.py:
import archicv.archi as archi

#open an image as <"numpy.ndarray"> img = archi.open_image( "./image_input.png" )

#save <"numpy.ndarray"> as an image archi.save_image( "./image_output.jpg", img )



Read An Image

How to read an image as a variable at the class of numpy.ndarray.

Just input the file address and name with format,
and output a variable at the class of numpy.ndarray.

 ReadImage.py:
import archicv.archi as archi

#open an image as <"numpy.ndarray"> img = archi.open_image( "./image_input.png" )



Perspective Transform

Perspective transform an image within a white paper.

There are several algorithms to do this work.
One is via HoughLines to detect the contour of paper, and other two are via paper color to detect paper.
Below is two examples via color to detect a paper and perspective transform it. One is using white color to detect directly, the other is using K-means marchine learning to detect the paper.

left: image_input.png
right: image_perspective_transformed.jpg

 Perspective1.py:

import archicv.archi as archi

#open an image as <"numpy.ndarray">
img = archi.open_image( "./image_input.png" )

#directly detect paper color
img_tmp = archi.detect_white_paper( img )

#zyw denoising
img_tmp = archi.zyw_denoising( img_tmp )

#find the contour of paper
contour = archi.find_contour_points( img_tmp, thresh_mode=0 )

#find four corner points of paper
points = archi.find_contour_points( contour )

#perspective transform
img_output = archi.perspective_transform( img, points )

#save image
archi.save_image( "./image_perspective_transformed.jpg", img_output )

 Perspective2.py:

import archicv.archi as archi

#open an image as <"numpy.ndarray">
img = archi.open_image("./image_input.png")

#K-means to detect paper color
img_tmp = archi.separate_color( img, 1 )[0]

#get a grayscale image
img_tmp = archi.get_gray_image( img_tmp )

#find the contour of paper
contour = archi.find_contour_points( img_tmp, thresh_mode=0 )

#find four corner points of paper
points = archi.find_contour_points( contour )

#perspective transform
img_output = archi.perspective_transform( img, points )

#save image
archi.save_image( "./image_perspective_transformed.jpg", img_output )



Get A Gray Image

Transform an image to a grayscale image.

Input a colorscale image at the class of numpy.ndarray,
and output a variable which is the grayscale image at class of numpy.ndarray.

 GrayScale.py:
import archicv.archi as archi

#open an image as <"numpy.ndarray"> img = archi.open_image("./image_perspective_transformed.jpg")

#get a grayscale image as <"numpy.ndarray"> img_gray = archi.get_gray_image( img )



Separate Color

Use K-means to separate multiple meaningful colors in one image.

Each kind of color has one meaning, such like buildings or lakestrand or others.
So for recognition, multiple colors should be separated to different image matrixs.
This is doing how to separate different colors through K-means algorithms.

 Separate.py:
import archicv.archi as archi

#open an image as <"numpy.ndarray"> img = archi.open_image("./image_input.jpg")

#set n n = 3

#separate colors to 3 kinds img_list = archi.separate_color( img, n )

#save each result image for i in xrange(n): archi.save_image( "./image_output" + str(i) + ".jpg", img_list[i] )

pic1: image_input.jpg            pic2: image_output0.jpg          pic3: image_output1.jpg        pic4: image_output2.jpg


Close Gaps

Close gaps at a selected value.

Hand drawing is also not accurate so that there are small gaps which will affect recognition program performance.
Function of close gaps at a selected value is required.
left: image_input.png
right: image_gap_closed.jpg

 CloseGaps.py:

import archicv.archi as archi

#open an image as <"numpy.ndarray">
img = archi.open_image( "./image_input.png" )

#set n
n = 12

#close gaps below n pixels
img_output = archi.close_gap( img, n )

#save image
archi.save_image( "./image_gap_closed.jpg", img_output )



Recognize Buildings

Recognization of which are buildings, Optimization, Drawing.

There are different kinds of drawing buildings on a plan picture.
It is often wise to uniform an easiest kind of drawing for eaier drawing and easier recognization.
So just drawing the contour of buildings is the wisest way to express the landscape planning and design.
Then detect the contour and optimize the results from the need of working of a landscape architect.
There are three kinds of results output, and they are cad results, json datas and image file from OpenCV.
At the example below, it will show two kinds of results, cad result and image file output via OpenCV.
Now there are still some bugs of recognize of some special cases of buildings, such as courtyard combination.
For wise develop, less is more, and it only recognizes the rectangle and overlooks other kinds.

left: image_input.png
right: image_roof_result.jpg

 CloseGaps.py:

#For less coding to change another kind of import
from archicv.archi import *

#open an image as <"numpy.ndarray">
img = open_image( "./image_input.png" )

#set a black paper for painting results
img_black_paper = create_paper(img.shape)

#get a grayscale image
img_gray = get_gray_image(img)

#begin recognition and optimization
contours = get_contour_cornerlists( img_gray )
rectangles = [ get_rectangle(contour) for contour in contours ]
rectangles = machine_classify( rectangles )
rectangles_four_points = machine_optimize( rectangles )

#draw results image file via OpenCV
for list_of_roof in rectangles_four_points:
    cv_draw_roof( img_black_paper, list_of_roof )
save_image('image_roof_result.jpg', img_black_paper )

#generate cad results
tmp_dxf = open_dxf()
for list_of_roof in rectangles_four_points:
    dxf_draw_roof( tmp_dxf, list_of_roof )
save_dxf( tmp_dxf, 'roof_result.dxf' )



Recognize circle tree

Recognization of circle tree.

The api of get_circle_tree() is not mature enough.
But it can works and this api is not the most important.
In drawing work of landscape architect, circle tree drawing is not the toughest jobs.
So it's not the best area for costing develop working.
There are two kinds of algorithms to detect circle tree. One is HoughCircle algorithms, and the other is find contours and calculate to get the circle, which is used in archi.get_circle_tree().

left: image_input.png
right: image_circle_tree_result.jpg

 CloseGaps.py:

from archicv.archi import *

#open an image as <"numpy.ndarray">
img = open_image( "./image_input.png" )

#set a black paper for painting results
img_black_paper = create_paper(img.shape)

#get a grayscale image
img_gray = get_gray_image(img)

#begin recognition and optimization
circles = get_circle_tree( img_gray )

#draw results image file via OpenCV
cv_draw_tree( img_black_paper, circles )
save_image( 'image_circle_tree_result.jpg', img_black_paper )

#generate cad results
tmp_dxf = open_dxf()
dxf_draw_tree( tmp_dxf, circles )
save_dxf( tmp_dxf, 'circle_tree_result.dxf' )



Recognize tree revclound

Recognization of tree revclound.

Data analysis and drawing of tree revclound are not mature enough.
But it can works and this api will be updated later.

left: image_input.png
right: image_revclound_tree_result.jpg

 CloseGaps.py:

from archicv.archi import *

#open an image as <"numpy.ndarray">
img = open_image( "./image_input.png" )

#set a black paper for painting results
img_black_paper = create_paper(img.shape)

#get a grayscale image
img_gray = get_gray_image(img)

#begin recognition and optimization
contours = get_contour_cornerlists( img_gray )

#draw results image file via OpenCV
cv_draw_revclound( img_black_paper, contours )
save_image( 'image_revclound_tree_result.jpg', img_black_paper )

#generate cad results
tmp_dxf = open_dxf()
dxf_draw_tree( tmp_dxf, contours )
save_dxf( tmp_dxf, 'revclound_tree_result.dxf' )



Recognize lake strandline

Recognization of lake strandline.

Close gaps and detect the contours of lake strandlines, including island strandline in lake.

left: image_input.png
right: image_lake_result.jpg

 CloseGaps.py:

from archicv.archi import *

#open an image as <"numpy.ndarray">
img = open_image( "./image_input.png" )

#set a black paper for painting results
img_black_paper = create_paper(img.shape)

#get a grayscale image
img_gray = get_gray_image(img)

#begin recognition and optimization
contours = get_contour_cornerlists( img_gray )

#draw results image file via OpenCV
cv_draw_lake( img_black_paper, contours )
save_image( 'image_lake_result.jpg', img_black_paper )

#generate cad results
tmp_dxf = open_dxf()
dxf_draw_tree( tmp_dxf, contours )
save_dxf( tmp_dxf, 'lake_result.dxf' )



Some Hints

Some tips for deep user. More details are in the reference.

1. This is a simple library and it is rather recommended to master every api in reference. Different api can combine to get different performance. It is worth dive into archicv api, especially for landscape architect.
2. If you are a deep enough user or a geek, it is recommended to learn opencv-python and numpy, because archicv is based on opencv and numpy. If you master opencv, you will discover archicv is just a easier library for users on the area of landscape architecture and archicv will make something easier if you are doing something about computer vision on landscape architecture. It is a short but good saber.
3. Because there are just several thousand lines of codes. So it is recommended to read the codes of archi.py in order to catch insights into code structure and logic.

About

Create a new man-machine interactive way for LA workers to hold on their landscape faith and do the true LA.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%