Giter Site home page Giter Site logo

pashaalex / mesh_augmentator Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 18.39 MB

Allows you to bend an image in 3D space. It is also acceptable to change lighting, shadows and depth of field

License: MIT License

Python 35.50% C++ 57.31% C 5.31% Makefile 1.88%
augmentation computer-vision

mesh_augmentator's Introduction

This project is used to augment paper images based on position, curl, and lighting.
Demo <- Demo without depth of field.

Quick start for augment images

Prepare data for augment

import cv2
import numpy as np
from mesh_augmentator import get_random_augment
from os import listdir
from os.path import isfile, join

# get any control points to be set on image
points_src = []
with open("rects.txt") as file:    
    for line in [line.rstrip() for line in file]:
        x, y, w, h = [float(a) for a in line.split(':')[1].split(';')]
        points_src.append((x, y))

In case of many images with background

image = cv2.imread('sample.jpg')
root = 'bgs'
background_fnames = [join(root, f) for f in listdir(root) if isfile(join(root, f))]

# get result image and control points
image, points = get_random_augment(image, 224, 200, points = points_src, backgrounds = None, background_fnames = background_fnames)

# draw control points on result augmented image
for x, y in points:
    cv2.circle(image, (int(x), int(y)), radius=3, color=(0, 0, 255), thickness=-1)
cv2.imwrite('output1.jpg', image)

In case of one or more background images in memory

image = cv2.imread('sample.jpg')
blank_image = np.zeros((224, 200, 3), np.uint8)

# get result image and control points
image, points = get_random_augment(image, 224, 200, points = points_src, backgrounds = [blank_image], background_fnames = None)

# draw control points on result augmented image
for x, y in points:
    cv2.circle(image, (int(x), int(y)), radius=3, color=(0, 0, 255), thickness=-1)
cv2.imwrite('output2.jpg', image)

Information about mesh render

import cv2
from mesh_augmentator import MeshModel

output_dim = 224
#prepare data
sample = cv2.imread('sample.jpg')
h, w, dc = sample.shape
k = min(output_dim / h, output_dim / w) * 2.2
sample = cv2.resize(sample, (int(w * k), int(h * k)), interpolation = cv2.INTER_LINEAR)
h, w, dc = sample.shape
background = cv2.imread('wood.jpg')
background = cv2.resize(background, (output_dim, output_dim), interpolation = cv2.INTER_LINEAR)

#render
mesh = MeshModel(100, 100, sample, True, True)
mesh.cylynder_vertical(R = w * 8)
mesh.shift(0, 0, mesh.get_best_object_distance())

mesh.set_output_size(output_dim, output_dim)
output_image = mesh.render(background)
cv2.imwrite("output.jpg", output_image)

Depth of field:
Depth of field

Light position change:
Light position change

Light diameter change:
Light diameter

Shadow:
Shadow

Rotate and curl:
Rotate

mesh_augmentator's People

Contributors

pashaalex avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.