-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageClean.py
71 lines (56 loc) · 2.17 KB
/
ImageClean.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
import cv2
import sys
from PIL import Image
from resizeimage import resizeimage
"""
3264x2448 orginal image
2448x2448 resized image
69 derece görüş açısı vertical
86 derece görüş açısı horizintal
100 derece görüş açısı diagonal
5 metre yükseklik de ortalama 7(687cm) metre görüş (vertical acida)
5 metre yükseklik de ortalama 10(1000cm) metre görüş( horizintal açıda)
eşit kenar resim de (2448x2448) vertical(69) açıyla 687 cm görüş saglar.
her bir piksel ortalama 0.3 cm (0.2806372549)
"""
class ImageCleaner:
def __init__(self, output):
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
cv2.imwrite('resim/capture.jpg', frame)
#cv2.imshow('frame', rgb)
cap.release()
#cv2.destroyAllWindows()
self.image = "resim/capture.jpg"
self.out = output
image = Image.open(self.image)
x, y = image.size
image = resizeimage.resize_cover(image, [x/2, y/2])
width, height = image.size
print(width, height)
# red green blue
for i in range(width):
for j in range(height):
r, g, b = image.getpixel((i, j))
if r > 100 and g < 100 and b < 100:
image.putpixel((i, j), (255, 0, 0))
elif r < 100 and g > 100 and b < 100:
image.putpixel((i, j), (0, 255, 0))
elif r < 100 and g < 100 and b > 100:
image.putpixel((i, j), (0, 0, 255))
# Process every pixel
for i in range(width):
for j in range(height):
r, g, b = image.getpixel((i, j))
if r > 100 and g > 100 and b > 100:
image.putpixel((i, j), (255, 255, 255))
elif r < 100 and g < 100 and b < 100:
image.putpixel((i, j), (0, 0, 0))
self.image = image
self.image.save(self.out)
def result(self):
return self.image
if __name__ == '__main__':
cleaner = ImageCleaner("resim/Finder_result.jpg")