Commit ba6a4986 authored by Caio Farias's avatar Caio Farias
Browse files

init

parent bf7fb014
vcomp
.vscode
\ No newline at end of file
# vComp
Atividades e exercícios da disciplina de Visão Computacional 2020.6
\ No newline at end of file
Atividades e exercícios da disciplina de Visão Computacional 2020.6
appdirs==1.4.4
apturl==0.5.2
astroid==2.4.2
autopep8==1.5.4
black==20.8b1
blinker==1.4
Brlapi==0.7.0
certifi==2019.11.28
chardet==3.0.4
click==7.1.2
colorama==0.4.3
command-not-found==0.3
cryptography==2.8
cupshelpers==1.0
dbus-python==1.2.16
defer==1.0.6
distlib==0.3.1
distro==1.4.0
distro-info===0.23ubuntu1
entrypoints==0.3
filelock==3.0.12
httplib2==0.18.0
idna==2.8
importlib-metadata==1.5.0
isort==5.5.2
keyring==18.0.1
language-selector==0.1
launchpadlib==1.10.13
lazr.restfulclient==0.14.2
lazr.uri==1.0.3
lazy-object-proxy==1.4.3
louis==3.12.0
macaroonbakery==1.3.1
Mako==1.1.0
MarkupSafe==1.1.0
mccabe==0.6.1
more-itertools==4.2.0
mypy-extensions==0.4.3
netifaces==0.10.4
numpy==1.19.2
oauthlib==3.1.0
olefile==0.46
opencv-python==4.4.0.42
pathspec==0.8.0
pbr==5.5.0
pexpect==4.6.0
Pillow==7.0.0
protobuf==3.6.1
pycairo==1.16.2
pycodestyle==2.6.0
pycups==1.9.73
PyGObject==3.36.0
PyJWT==1.7.1
pylint==2.6.0
pymacaroons==0.13.0
PyNaCl==1.3.0
PyQt5==5.15.1
PyQt5-sip==12.8.1
pyRFC3339==1.1
python-apt==2.0.0+ubuntu0.20.4.1
python-dateutil==2.7.3
python-debian===0.1.36ubuntu1
pytz==2019.3
pyxdg==0.26
PyYAML==5.3.1
regex==2020.7.14
reportlab==3.5.34
requests==2.22.0
requests-unixsocket==0.2.0
SecretStorage==2.3.1
simplejson==3.16.0
sip==4.19.21
six==1.14.0
stevedore==3.2.2
systemd-python==234
toml==0.10.1
typed-ast==1.4.1
typing-extensions==3.7.4.3
ubuntu-advantage-tools==20.3
ubuntu-drivers-common==0.0.0
ufw==0.36
unattended-upgrades==0.1
urllib3==1.25.8
usb-creator==0.3.7
virtualenv==20.0.31
virtualenv-clone==0.5.4
virtualenvwrapper==4.8.4
wadllib==1.3.3
wrapt==1.12.1
xkit==0.0.0
yapf==0.30.0
zipp==1.0.0
import cv2
import numpy as np
import sys
def resize(img, percentage):
h = int(img.shape[0] * percentage)
w = int(img.shape[1] * percentage)
return cv2.resize(img, (w, h))
def joinCH(path):
img = cv2.imread(path)
img = resize(img, .15)
B = img[:, :, 0]
G = img[:, :, 1]
R = img[:, :, 2]
BGR = np.hstack((B, G, R))
bgr_concat = np.concatenate((B, G, R), axis=1)
cv2.imshow('img -> BGR', bgr_concat)
cv2.waitKey(0)
cv2.destroyAllWindows()
joinCH(sys.argv[1])
import cv2
import numpy as np
import sys
def resize(img, percentage):
h = int(img.shape[0] * percentage)
w = int(img.shape[1] * percentage)
return cv2.resize(img, (w, h))
def reflextAxis1(path):
img = cv2.imread(path)
img = resize(img, .33)
new_img = np.flip(img, axis=1)
compare = np.concatenate((img, new_img), axis=1)
cv2.imshow('normal -> invert', compare)
cv2.waitKey(0)
cv2.destroyAllWindows()
reflextAxis1(sys.argv[1])
import cv2
import numpy as np
import sys
def resize(img, percentage):
h = int(img.shape[0] * percentage)
w = int(img.shape[1] * percentage)
return cv2.resize(img, (w, h))
def blending(A, B):
if(A.shape == B.shape):
C = np.zeros(A.shape, dtype=A.dtype)
C = np.add(A // 2, B // 2)
return C
else:
print("As imagens possuem dimensões diferentes.")
def image_blender(path1, path2):
img_tiger = resize(cv2.imread(path1), .5)
img_toucan = resize(cv2.imread(path2), .5)
blend_img = blending(img_tiger, img_toucan)
cv2.imshow('blending', blend_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
image_blender(sys.argv[1], sys.argv[2])
import numpy as np
import cv2
import sys
def generate_gradient(w, h):
width = int(w)
height = int(h)
matrix = np.zeros((width, height), dtype=np.uint8)
for j in range(0, matrix.shape[0]):
matrix[j][:] = np.add(matrix[j][:], int(255 * j/height))
cv2.imshow('new-matrix', matrix)
cv2.waitKey(0)
cv2.destroyAllWindows()
generate_gradient(sys.argv[1], sys.argv[2])
import cv2
import numpy as np
import sys
def resize(img, percentage):
h = int(img.shape[0] * percentage)
w = int(img.shape[1] * percentage)
return cv2.resize(img, (w, h))
def filter(path_args, proportion=.5):
first = True
n_images = len(path_args)
for i in range(1, n_images):
print('Processando a seguinte imagem: ' + path_args[i])
current_image = resize(cv2.imread(path_args[i], 0), proportion)
if(first):
output = np.zeros((current_image.shape[0], current_image.shape[1]), dtype=np.float)
output = current_image // n_images
first = False
output = np.clip(np.add(output, current_image // n_images), 0, 255)
cv2.imshow(f'{n_images} imagens contabilziadas', output)
cv2.waitKey(0)
cv2.destroyAllWindows()
filter(sys.argv, proportion=.5)
import cv2
import numpy as np
import sys
def resize(img, percentage):
h = int(img.shape[0] * percentage)
w = int(img.shape[1] * percentage)
return cv2.resize(img, (w, h))
def increase_bringhtness_and_paint_bars(args):
img = resize(cv2.imread(args[1], 0), .5)
brightness = int(args[2])
d = int(args[3])
stripe_size = int(args[4])
output = np.zeros((img.shape[0], img.shape[1]), dtype=np.uint8)
for j in range(stripe_size, img.shape[1], stripe_size + d):
output[:, j:j+d] = np.clip(np.add(img[:, j:j+d], brightness, dtype=np.float), 0, 255)
cv2.imshow('output', output)
cv2.imwrite(args[5], output)
cv2.waitKey(0)
cv2.destroyAllWindows()
increase_bringhtness_and_paint_bars(sys.argv)
\ No newline at end of file
import cv2
import numpy as np
import sys
def generate_auxM(matrix, i, j, kernel_size):
ouput = matrix[i][j:j + kernel_size]
for step in range(1, kernel_size):
ouput = np.vstack((ouput, matrix[i + step][j:j + kernel_size]))
return ouput
def resize(img, percentage):
h = int(img.shape[0] * percentage)
w = int(img.shape[1] * percentage)
return cv2.resize(img, (w, h))
def generate_kernel(size_kernel):
return np.ones((size_kernel, size_kernel), dtype=np.float)/(size_kernel ** 2)
def smooth_filter(args):
img = cv2.cvtColor(cv2.imread(args[1]), cv2.COLOR_BGR2GRAY)
kernel = generate_kernel(9)
kernel_padding = kernel.shape[0] - 1
kernel_size = kernel.shape[0]
output = np.zeros(img.shape, dtype=np.uint8)
"""Faz operações com o kernel e a imagem"""
for i in range(kernel_padding - 1, img.shape[0] - kernel_padding):
for j in range(kernel_padding - 1, img.shape[1] - kernel_padding):
aux_mat = generate_auxM(img, i, j, kernel_size)
output[i, j] = np.clip(np.sum(aux_mat * kernel), 0, 255)
cv2.imshow('after', output)
cv2.imwrite(args[2], output)
cv2.waitKey(0)
cv2.destroyAllWindows()
smooth_filter(sys.argv)
import cv2
import numpy as np
import sys
def generate_auxM(matrix, i, j, kernel_size):
ouput = matrix[i][j:j + kernel_size]
for step in range(1, kernel_size):
ouput = np.vstack((ouput, matrix[i + step][j:j + kernel_size]))
return ouput
def resize(img, percentage):
h = int(img.shape[0] * percentage)
w = int(img.shape[1] * percentage)
return cv2.resize(img, (w, h))
def generate_kernel(size_kernel):
return np.ones((size_kernel, size_kernel), dtype=np.float)/(size_kernel ** 2)
def grad_magnetude(matrix):
sobel_x = np.array([[-1/2, 0, 1/2], [-2/4, 0, 2/4], [1/4, 0, 1/4]])
sobel_y = np.array([[-1/4, -2/4, -1/4], [0, 0, 0], [1/4, 2/4, 1/4]])
x_magnetude = np.sum(matrix * sobel_x)
y_magnetude = np.sum(matrix * sobel_y)
magnetude = np.linalg.norm([x_magnetude, y_magnetude])
return magnetude
def selective_smooth_filter(args):
img = resize(cv2.imread(args[1], 0), 1)
kernel = generate_kernel(3)
kernel_padding = kernel.shape[0] - 1
kernel_size = kernel.shape[0]
output = np.zeros(img.shape, dtype=np.uint8)
c = .75
max_grad_value = c * 255 * kernel_size
for i in range(kernel_padding - 1, img.shape[0] - kernel_padding):
for j in range(kernel_padding - 1, img.shape[1] - kernel_padding):
aux_mat = generate_auxM(img, i, j, kernel_size)
magnetude = int(grad_magnetude(aux_mat))
if(magnetude < max_grad_value ):
output[i, j] = np.clip((np.sum(aux_mat * kernel)), 0, 255)
else:
output[i, j] = img[i, j]
cv2.imshow('after', output)
cv2.imwrite('output-3py.jpg', output)
cv2.waitKey(0)
cv2.destroyAllWindows()
selective_smooth_filter(sys.argv)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment