Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
мне лично очень мешает, что при переходе фотография в начале стоит на месте (во время микса), и только потом начинает двигаться
большинство фотографов кроме как ФШ да ЛР ничего и не умеют, и даже винду переставить не могут
либо делать backup, либо RaidРезервная копия не заменяет RAID-массив и наоборот.
# The distance between green marks shuold be at least 4a, where "a" is the width of the square.
# It's easier to draw the area around the central point between them.
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
def nothing(x):
pass
cv2.namedWindow('mask')
# Create sliders for range adjusting
cv2.createTrackbar('Hue_low', 'mask', 40, 255, nothing)
cv2.createTrackbar('Hue_high', 'mask', 76, 255, nothing)
cv2.createTrackbar('Saturation_low', 'mask', 81, 255, nothing)
cv2.createTrackbar('Saturation_high', 'mask', 255, 255, nothing)
while True:
# flashing the counter
centrIndex = 0
# init list
centroidListX = []
centroidListY = []
# Take each frame
_, frame = cap.read()
# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# Get current slider position
Hue_low = cv2.getTrackbarPos('Hue_low', 'mask')
Hue_high = cv2.getTrackbarPos('Hue_high', 'mask')
Sat_low = cv2.getTrackbarPos('Saturation_low', 'mask')
Sat_high = cv2.getTrackbarPos('Saturation_high', 'mask')
# define range of green color in HSV
lower_green = np.array([Hue_low, Sat_low, 40])
upper_green = np.array([Hue_high, Sat_high, 250])
# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower_green, upper_green)
#Erode disabled to speedup. Works nice without it.
mask = cv2.erode(mask, None, iterations = 1)
mask = cv2.dilate(mask, None, iterations = 1)
# Bitwise-AND mask and original image
image_result = cv2.bitwise_and(frame, frame, mask=mask)
# Detecting edges
image_mask_blur = cv2.medianBlur(mask, 3)
image_canny = cv2.Canny(image_mask_blur, 30, 150)
# Closing gaps
kernel_canny = cv2.getStructuringElement(cv2.MORPH_RECT, (7, 7))
image_canny_closed = cv2.morphologyEx(image_canny, cv2.MORPH_CLOSE, kernel_canny)
# Finding contours
(cnts, _) = cv2.findContours(image_canny_closed.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in cnts:
# approximate the contour
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.03 * peri, True)
# get the bounding box with it's coordinates and aspect ratio
(x,y,w,h) = cv2.boundingRect(approx)
aspectRatio = w / float(h)
# initialize bool variables
boolRectangle = False
boolPeri = False
boolAspect = False
if len(approx) >= 4 and len(approx) <= 6:
boolRectangle = True
if peri >= 50:
boolPeri = True
if aspectRatio > 0.9 and aspectRatio < 1.1:
boolAspect = True
if boolRectangle and boolPeri and boolAspect:
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
# get centroid of rectangle
centroidX = x + w/2
centroidY = y + h/2
centroidListX.append(centroidX)
centroidListY.append(centroidY)
cv2.circle(frame, (centroidListX[centrIndex], centroidListY[centrIndex]), 1,(0,0,255),3)
centrIndex += 1
if centrIndex == 4:
centroidMainX = 0
centroidMainY = 0
for loopIndex in range(0, 3):
centroidMainX = centroidMainX + centroidListX[loopIndex]
centroidMainY = centroidMainY + centroidListY[loopIndex]
centroidMainX = centroidMainX/4
centroidMainY = centroidMainY/4
cv2.circle(frame, (centroidMainX, centroidMainY), 5, (0, 0, 255),3)
cv2.rectangle(frame, (centroidMainX - int(peri),centroidMainY + int(peri)), (centroidMainX + int(peri), centroidMainY - int(peri)), (0,255,255), 2)
cv2.imshow('frame', frame)
# Visualization
cv2.imshow('mask', image_result)
#cv2.imshow('canny_closed', image_canny_closed)
#cv2.imshow('canny', image_canny)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
...Programming as a profession is only moderately interesting. It can be a good job, but you could make about the same money and be happier running a fast food joint. You're much better off using code as your secret weapon in another profession.
Вот крайне интересно читать о том, как программирование помогает «обычным людям» в решии их повседневных задач.+1 решение проблем — это самый кайф в нашем деле!
Например, на очереди статья, как сделать вот такую милую и функциональную фотобудку
from PIL import Image,ExifTags
img=Image.open(PATH_TO_IMAGE)
exif=dict((ExifTags.TAGS[k], v) for k, v in img._getexif().items() if k in ExifTags.TAGS)
ffmpeg -i "concat:input1.mpg|input2.mpg|input3.mpg" -c copy output.mpg
Linux в кармане — на службе у фотографа