Skip to content

Instantly share code, notes, and snippets.

@larien
Created March 7, 2019 23:35
Show Gist options
  • Save larien/0611e993fad280c8d48210738e0f26f6 to your computer and use it in GitHub Desktop.
Save larien/0611e993fad280c8d48210738e0f26f6 to your computer and use it in GitHub Desktop.
Processamento de Imagens - 07-03 (aula 3)
import cv2
img = cv2.imread("data/lena.jpg")
cv2.imshow('Img',img)
print('Shape: ', img.shape)
print('Size: ' , img.size)
print('Type: ' , img.dtype)
cv2.waitKey()
cv2.destroyAllWindows()
import cv2
img = cv2.imread("data/lena.jpg", cv2.IMREAD_GRAYSCALE)
cv2.imshow('Img',img)
cv2.imwrite('newfile.jpg', img)
print("Tom de cinza aplicado")
cv2.waitKey()
cv2.destroyAllWindows()
import cv2
cap = cv2.VideoCapture("drop.avi")
while cap.isOpened():
ret, frame = cap.read()
cv2.imshow('Camera', frame)
if cv2.waitKey(15) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
import cv2
cap = cv2.VideoCapture(0)
while True :
ret, frame = cap.read()
cv2.imshow('Camera', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
import cv2
imgRGB = cv2.imread('../data/lena.jpg')
imgGray = cv2.cvtColor(imgRGB, cv2.COLOR_BGR2GRAY)
#Numpy is a optimized library for fast array calculations.
#So simply accessing each and every pixel values and modifyin it will be very slow and it is discouraged.
#get RGB pixel value at 100x100
pixel = imgRGB[100,100]
#print rgb value of pixel
print('RGB value: ', pixel)
#get Gray pixel value at 100x100
pixel = imgGray[100,100]
#print gray scale value of pixel
print('Gray pixel: ', pixel)
#set green to position
imgRGB[100,100] = [0,255,0]
#set white to position
imgGray[100,100] = 255
cv2.imshow('RGB Edit pixel image',imgRGB)
cv2.imshow('Gray Edit pixel image',imgGray)
cv2.waitKey()
cv2.destroyAllWindows()
import cv2
imgRGB = cv2.imread('../data/lena.jpg')
#cria um ROI - Region of Interest
roi = imgRGB[200:400, 200:400]
final = imgRGB.copy()
final[0:200, 0:200] = roi
final[imgRGB.shape[0]-200:imgRGB.shape[0],
imgRGB.shape[1]-200:imgRGB.shape[1]] = roi
cv2.imshow('RGB image',imgRGB)
cv2.imshow('ROI mage',roi)
cv2.imshow('Final mage',final)
cv2.waitKey()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment