Answer the question
In order to leave comments, you need to log in
How to get the horizon line in the spatial position indicator?
There is an image.
You need to get something like
, i.e., find the border between black (ground) and blue (sky),
There is shit code:
from PIL import ImageOps, Image, ImageGrab
import numpy as np
import cv2
def getSkyThresh(img): # находит все голубые места
hsv_min = np.array((19, 100, 100))
hsv_max = np.array((35, 255, 255))
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
return cv2.inRange(hsv, hsv_min, hsv_max)
def getGNDthresh(img): # находит все серые места (соответствующие земле)
hsv_min = np.array((0, 0, 0))
hsv_max = np.array((255, 0, 130))
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
return cv2.inRange(hsv, hsv_min, hsv_max)
def getRedThresh(img): # находит все красные места (риски и символическое изображение самолета)
hsv_min = np.array((100, 0, 0))
hsv_max = np.array((130, 255, 255))
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
return cv2.inRange(hsv, hsv_min, hsv_max)
def getFullThsesh(img):
skyThresh = getSkyThresh(img)
GNDtresh = getGNDthresh(img)
redThresh = getRedThresh(img)
print(skyThresh)
x, y = np.shape(img)[0], np.shape(img)[1]
img1 = np.array([[0 for i in range(y)] for j in range(x)])
center = (93, 98)
radius = 86
for i in range(x):
for j in range(y):
if (i - center[0]) ** 2 + (j - center[1]) ** 2 > radius ** 2:
img1[i, j] = 50
elif redThresh[i, j] != 0:
img1[i, j] = 100
elif GNDtresh[i, j] != 0:
img1[i, j] = 170
elif skyThresh[i, j] != 0:
img1[i, j] = 255
return img1
def getLine(img): # должен выделять линию
skyThresh = getSkyThresh(img)
GNDtresh = getGNDthresh(img)
redThresh = getRedThresh(img)
print(skyThresh)
x, y = np.shape(img)[0], np.shape(img)[1]
img1 = np.array([[0 for i in range(y)] for j in range(x)])
center = (93, 98)
radius = 86
for i in range(x):
for j in range(y):
if (i - center[0]) ** 2 + (j - center[1]) ** 2 <= radius ** 2 and redThresh[i, j] == 0 and \
GNDtresh[i, j] == 0 and skyThresh[i, j] == 0:
img1[i, j] = 255
return img1
img1 = cv2.imread('filename') # читаем изображение
Image.fromarray(img1).show() # показываем его
Image.fromarray(getFullThsesh(img1)).show() # здесь и далее магия
Image.fromarray(getLine(img1)).show()
getLine()
highlights not only the line, but also various other things. I would like to highlight only the line. What if so: Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question