예제 #1
0
파일: cannyTest.py 프로젝트: GatoY/justFace
import cv2
import gorgeous
import faceDetect
import picKit
import edge
import copy
img = cv2.imread('test.jpeg')
height, width = img.shape[:2]
img = picKit.resize(img, 500, width * 500 / height)
faces = faceDetect.faceDetect(img)
newimg = copy.copy(img)
for (x, y, w, h) in faces:
    newimg = cv2.rectangle(newimg, (x, y), (x + w, y + h), (255, 0, 0), 2)
    edgeImage = edge.canny(img[(y - 20):(y + h + 20), (x - 20):(x + w + 20)])
    image, contours, hierarchy = cv2.findContours(copy.copy(edgeImage),
                                                  cv2.RETR_TREE,
                                                  cv2.CHAIN_APPROX_SIMPLE)
    image = cv2.drawContours(edgeImage, contours, 1, (255, 255, 255), 3)
    cv2.imshow('edges', image)
    cv2.waitKey()

cv2.imshow('image', newimg)
cv2.waitKey()
img = gorgeous.gorgeous(img, faces, 8)
cv2.imshow('image2', img)
cv2.waitKey()
예제 #2
0
import cv2
import picKit
import numpy as np
import edge
np.set_printoptions(threshold=np.inf)
img =cv2.imread('test.jpeg')
height, width =img.shape[:2]
img = picKit.resize(img,500,width*500/height)
img = edge.canny(img)
image, contours, hierarchy = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
#cv2.imshow('im',contours)
#cv2.waitKey()
print contours
예제 #3
0
import cv2
import gorgeous
import faceDetect
import picKit
import edge
import copy
img = cv2.imread('test.jpeg')
height, width =img.shape[:2]
img = picKit.resize(img,500,width*500/height)
edges = edge.canny(img)
cv2.imshow('image',edges)
cv2.waitKey()
예제 #4
0
# Implement **`canny`** in `edge.py` using the functions you have implemented so far. Test edge detector with different parameters.
#
# Here is an example of the output:
#
# ![iguana_edges.png](iguana_edges.png)
#
# We provide the correct output and the difference between it and your result for debugging purposes.  If you see white spots in the Difference image, you should check your implementation.

#%%
from edge import canny

# Load image
img = io.imread('iguana.png', as_gray=True)

# Run Canny edge detector
edges = canny(img, kernel_size=5, sigma=1.4, high=0.03, low=0.02)
print(edges.shape)

plt.subplot(1, 3, 1)
plt.imshow(edges)
plt.axis('off')
plt.title('Your result')

plt.subplot(1, 3, 2)
reference = np.load('references/iguana_canny.npy')
plt.imshow(reference)
plt.axis('off')
plt.title('Reference')

plt.subplot(1, 3, 3)
plt.imshow(edges ^ reference)
from edge import hough_transform
from edge import canny
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from time import time
from skimage import io
import PIL.Image

# Load image
img = io.imread('road.jpg', as_gray=True)

# Run Canny edge detector
edges = canny(img, kernel_size=5, sigma=1.4, high=0.03, low=0.02)
H, W = img.shape

# Generate mask for ROI (Region of Interest)
mask = np.zeros((H, W))
for i in range(H):
    for j in range(W):
        if i > (H / W) * j and i > -(H / W) * j + H:
            mask[i, j] = 1

# Extract edges in ROI
roi = edges * mask
acc, rhos, thetas = hough_transform(roi)

I8 = (((acc - acc.min()) / (acc.max() - acc.min())) * 255.9).astype(np.uint8)

img = PIL.Image.fromarray(I8)
img.save("file.png")