Worked on cv

This commit is contained in:
Lukas Wölfer
2019-04-22 15:26:12 +02:00
parent 3720e25a5a
commit 3077525efe
3 changed files with 59 additions and 31 deletions

View File

@@ -1,42 +1,45 @@
from .context import shenzhen_solitaire
from shenzhen_solitaire.cv import adjustment
from shenzhen_solitaire.cv import card_finder
from typing import Tuple, List, Dict
import cv2
import numpy
import itertools
A = cv2.imread("Solitaire.png")
adj = adjustment.adjust_field(A)
X = card_finder.get_field_squares(A, adj)
for h in range(20):
p = {None: 0}
for x in X[h]:
for x2 in ((x1[0], x1[1], x1[2]) for x1 in x):
if x2 in p:
p[x2] += 1
else:
p[x2] = 1
B = sorted(p.items(), key=lambda x: x[1])
print(*B, sep='\n')
T = X[h].copy()
cv2.imshow("Window", T)
while cv2.waitKey(0) != 27:
pass
cv2.destroyWindow("Window")
assert 0
for ix, vx in enumerate(T):
for iy, vy in enumerate(vx):
if (vy[0] > 100) and (vy[1] > 100) and (vy[2] > 100):
T[ix, iy] = [255, 255, 255]
def pixelcount(image: numpy.ndarray) -> List[Tuple[Tuple[int, int, int], int]]:
p: Dict[Tuple[int, int, int], int] = {(0, 0, 0): 0}
for pixel in itertools.chain.from_iterable(image):
x = tuple(pixel)
if x in p:
p[x] += 1
else:
T[ix, iy] = [0, 0, 0]
p[x] = 1
B = sorted(p.items(), key=lambda x: x[1])
return B
cv2.imshow("Window", T)
cv2.waitKey(0)
cv2.destroyWindow("Window")
def simplify(image: numpy.ndarray) -> None:
cv2.imshow("Window", image)
cv2.waitKey(0)
cv2.destroyWindow("Window")
print(*card_finder.simplify(image).items(), sep='\n')
cv2.imshow("Window", image)
cv2.waitKey(0)
cv2.destroyWindow("Window")
# for j in X:
# cv2.imshow("Window", j)
# cv2.waitKey(0)
def main() -> None:
adj = adjustment.adjust_field(A)
image_squares = card_finder.get_field_squares(A, adj)
for img in image_squares:
print(*pixelcount(img), sep='\n')
cv2.imshow("Window", img)
cv2.waitKey(0)
cv2.destroyWindow("Window")
print()
if __name__ == "__main__":
main()