Ошибка Process finished with exit code -1073741571 (0xC00000FD)
У неё по краям оранжевая рамка, которую мне нужно обрезать. Но для начала я решил раскрасить эта рамку в красный с помощью рекурсии, чтобы видеть как работает программа.
Вот основной код:
import sys
from PIL import Image
from color_class import Color
sys.setrecursionlimit(1000000489)
BORDER_COLOR = Color(255, 194, 61)
def color_diff(c1, c2):
print('def color diff')
color_d = c1 - c2
print('pass 2')
return sum([abs(i) for i in color_d])
def is_border_color(color):
print('def is_border_color')
if isinstance(color, tuple):
color = Color(*color)
print('pass')
print(BORDER_COLOR)
print(color)
color_d = color_diff(BORDER_COLOR, color) # Здесь происходит ошибка
print('color_d = ', color_d)
return color_d < 195
def draw_border(i, j, pixels, sz):
# Проверяем не выходим ли мы за границы массива
if i not in range(0, sz[1]) or j not in range(0, sz[0]):
return
print(i, j)
if not is_border_color(pixels[j, i]):
return
print('debug1')
pixels[j, i] = 255, 0, 0
print('debug2')
for pi in [-1, 0, 1]:
for pj in [-1, 0, 1]:
# Запускаем рекурсию из соседних клеток
draw_border(j + pj, i + pi, pixels, sz)
def cut_image(im_name):
im = Image.open(im_name)
pixels = im.load()
width, height = im.size
print(width, height) # 1018*1017
for coord in range(200): # Ищем начало рамки
if is_border_color(pixels[coord, coord]):
# При обнаружении рамки запускаем рекурсию, которая закрасит рамку в красный
draw_border(coord, coord, pixels, (width, height))
# Рекурсии. достаточно запустить один раз, поэтому сразу выходим из цикла
break
im.show()
if __name__ == '__main__':
cut_image('not_cutted.jpg')
Вот еще код класса цвета, который тоже используются в программе, но тут ничего интересного:
from random import randrange as rd
class Color:
def __init__(self, *args, color_range=(256, 256, 256)):
if args:
self.r, self.g, self.b = args
else:
if isinstance(color_range, Color):
color_range = color_range.tuple()
self.r, self.g, self.b = rd(0, color_range[0]), rd(0, color_range[1]), rd(0, color_range[2])
def __str__(self):
return f'Color({self.r}, {self.g}, {self.b})'
def __add__(self, other):
if isinstance(other, Color):
return Color(self.r + other.r, self.g + other.g, self.b + other.b)
elif isinstance(other, tuple):
return Color(self.r + other[0], self.g + other[1], self.b + other[2])
return Color(self.r + other, self.g + other, self.b + other)
def __sub__(self, other):
if isinstance(other, Color):
return Color(self.r - other.r, self.g - other.g, self.b - other.b)
elif isinstance(other, tuple):
return Color(self.r - other[0], self.g - other[1], self.b - other[2])
return Color(self.r - other, self.g - other, self.b - other)
def __mul__(self, other):
return Color(self.r * other, self.g * other, self.b * other)
def __mod__(self, other):
if isinstance(other, Color):
return Color(self.r % other.r, self.g % other.g, self.b % other.b)
elif isinstance(other, tuple):
return Color(self.r % other[0], self.g % other[1], self.b % other[2])
return Color(self.r % other, self.g % other, self.b % other)
def __imod__(self, other):
return self % other
def __floordiv__(self, other):
if isinstance(other, Color):
return Color(self.r // other.r, self.g // other.g, self.b // other.b)
elif isinstance(other, tuple):
return Color(self.r // other[0], self.g // other[1], self.b // other[2])
return Color(self.r // other, self.g // other, self.b // other)
def __ifloordiv__(self, other):
return self // other
def __iadd__(self, other):
return self + other
def __isub__(self, other):
return self - other
def __imul__(self, other):
return self * other
def __lt__(self, other):
if isinstance(other, Color):
return self.r < other.r and self.g < other.g and self.b < other.b
elif isinstance(other, tuple):
return self.r < other[0] and self.g < other[1] and self.b < other[2]
return self.r < other and self.g < other and self.b < other
def __iter__(self):
return iter([self.r, self.g, self.b])
def tuple(self):
return self.r, self.g, self.b
В результате работы программы вылазит ошибка:
Process finished with exit code -1073741571 (0xC00000FD)
Судя по выводу программы ошибка происходит в этой строчке
color_d = color_diff(BORDER_COLOR, color)
Причем в функцию color_diff программа не заходит. Вот я и не понимаю, где здесь, а главное почему ошибка происходит?!
Кто-нибудь может помочь?
