def image_callback(self, msg):
image = self.bridge.imgmsg_to_cv2(msg,desired_encoding='bgr8')
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
lower_yellow = numpy.array([18, 120, 200])
upper_yellow = numpy.array([28, 255, 255])
mask = cv2.inRange(hsv, lower_yellow, upper_yellow)
h, w, d = image.shape
search_top = 3*h/4
search_bot = 3*h/4 + 20
mask[0:search_top, 0:w] = 0
mask[search_bot:h, 0:w] = 0
M = cv2.moments(mask)
if M['m00'] > 0:
cx = int(M['m10']/M['m00'])
cy = int(M['m01']/M['m00'])
cv2.circle(image, (cx, cy), 20, (0,0,255), -1)
# BEGIN CONTROL
err = cx - w/2
self.twist.linear.x = 0.2
self.twist.angular.z = -float(err) / 100
self.cmd_vel_pub.publish(self.twist)
# END CONTROL
cv2.imshow("window", image)
cv2.waitKey(3)
python类COLOR_BGR2HSV的实例源码
def color_picker(rect):
global img,img_gray2,hsv
roi=img[rect[0][1]:rect[1][1],rect[0][0]:rect[1][0]]
b,g,r,_=np.uint8(cv2.mean(roi))
color=cv2.cvtColor(np.uint8([[[b,g,r]]]),cv2.COLOR_BGR2HSV)
h= color[0][0][0]
# define range of blue color in HSV
lower = np.array([h-10,50,50])
upper = np.array([h+10,255,255])
# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower, upper)
# Bitwise-AND mask and original image
res = cv2.bitwise_and(img,img, mask= mask)
res2=cv2.bitwise_and(img_gray2,img_gray2, mask= cv2.bitwise_not(mask))
return res+res2
fengjing_HSV_edit_with_inpaint_Background.py 文件源码
项目:Opencv_learning
作者: wjb711
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def draw_circle(event,x,y,flags,param):
#if event == cv2.EVENT_LBUTTONDBLCLK:
if event == cv2.EVENT_LBUTTONDOWN:
print ('mouse x and y is ')
print (x,y)
px = im1[y,x]
print ('RGB Value:')
print px
px_hsv = cv2.cvtColor(im1, cv2.COLOR_BGR2HSV)
H=px_hsv.item(y,x,0)
S=px_hsv.item(y,x,1)
V=px_hsv.item(y,x,2)
print ('HSV Value: H?S??V')
print (H,S,V)
def add_blobs(crop_frame):
frame=cv2.GaussianBlur(crop_frame, (3, 3), 0)
# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# define range of green color in HSV
lower_green = np.array([70,50,50])
upper_green = np.array([85,255,255])
# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower_green, upper_green)
mask = cv2.erode(mask, None, iterations=1)
mask = cv2.dilate(mask, None, iterations=1)
# Bitwise-AND mask and original image
res = cv2.bitwise_and(frame,frame, mask= mask)
detector = cv2.SimpleBlobDetector_create(params)
# Detect blobs.
reversemask=255-mask
keypoints = detector.detect(reversemask)
if keypoints:
print "found blobs"
if len(keypoints) > 4:
keypoints.sort(key=(lambda s: s.size))
keypoints=keypoints[0:3]
# Draw detected blobs as red circles.
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures the size of the circle corresponds to the size of blob
im_with_keypoints = cv2.drawKeypoints(frame, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
else:
print "no blobs"
im_with_keypoints=crop_frame
return im_with_keypoints #, max_blob_dist, blob_center, keypoint_in_orders
def print_img_array(self):
img = self.take_screenshot('array')
#converts image to HSV
img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# gets the values from the sliders
low_hue = self.low_hue.get()
low_sat = self.low_sat.get()
low_val = self.low_val.get()
# gets upper values from sliders
high_hue = self.high_hue.get()
high_sat = self.high_sat.get()
high_val = self.high_val.get()
lower_color = np.array([low_hue,low_sat,low_val])
upper_color= np.array([high_hue,high_sat,high_val])
#creates the mask and result
mask = cv2.inRange(self.hsv_image, lower_color, upper_color)
mask = np.array(mask)
mask.view
# Instance of Tkinter
def random_saturation(img, label, lower=0.5, upper=1.5):
"""
Multiplies saturation with a constant and clips the value between [0,1.0]
Args:
img: input image in float32
label: returns label unchanged
lower: lower val for sampling
upper: upper val for sampling
"""
alpha = lower + (upper - lower) * rand.rand()
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# saturation should always be within [0,1.0]
hsv[:, :, 1] = np.clip(alpha * hsv[:, :, 1], 0.0, 1.0)
return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR), label
def random_hue(img, label, max_delta=10):
"""
Rotates the hue channel
Args:
img: input image in float32
max_delta: Max number of degrees to rotate the hue channel
"""
# Rotates the hue channel by delta degrees
delta = -max_delta + 2.0 * max_delta * rand.rand()
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
hchannel = hsv[:, :, 0]
hchannel = delta + hchannel
# hue should always be within [0,360]
idx = np.where(hchannel > 360)
hchannel[idx] = hchannel[idx] - 360
idx = np.where(hchannel < 0)
hchannel[idx] = hchannel[idx] + 360
hsv[:, :, 0] = hchannel
return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR), label
def check_image(name):
expected_data = json.loads(open('./img/' + name + '.json').read())
if not expected_data['enabled']:
return
expected_targets = expected_data['targets']
img = cv2.imread('./img/' + name + '.jpg', cv2.IMREAD_COLOR)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
args = config.copy()
args['img'] = hsv
args['output_images'] = {}
actual_targets = find(**args)
# make sure same number of targets are detected
assert len(expected_targets) == len(actual_targets)
# targets is a list of 2-tuples with expected and actual results
targets = zip(expected_targets, actual_targets)
# compare all the different features of targets to make sure they match
for pair in targets:
expected, actual = pair
# make sure that the targets are close to where they are supposed to be
assert is_close(expected['pos']['x'], actual['pos']['x'], 0.02)
assert is_close(expected['pos']['y'], actual['pos']['y'], 0.02)
# make sure that the targets are close to the size they are supposed to be
assert is_close(expected['size']['width'], actual['size']['width'], 0.02)
assert is_close(expected['size']['height'], actual['size']['height'], 0.02)
def handle_image(img):
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
new_data_condition.acquire()
state['img'] = hsv
args = config['target'].copy()
args['img'] = hsv
args['draw_output'] = state['draw_output']
args['output_images'] = {}
targets = vision.find(**args)
state['targets'] = targets
state['output_images'] = args['output_images']
new_data_condition.notify_all()
new_data_condition.release()
fps, processing_time = update_fps()
state['fps'] = round(fps, 1)
print 'Processed in', processing_time, 'ms, max fps =', round(fps_smoothed, 1)
def execute_ColorSpace(proxy,obj):
try: img=obj.sourceObject.Proxy.img.copy()
except: img=cv2.imread(__dir__+'/icons/freek.png')
hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
lower = np.array([max(obj.h1-obj.h2,0),max(obj.s1-obj.s2,0),max(obj.v1-obj.v2,0)])
upper = np.array([min(obj.h1+obj.h2,255),min(obj.s1+obj.s2,255),min(obj.v1+obj.v2,255)])
say("ee")
say(lower)
say(upper)
mask = cv2.inRange(hsv, lower, upper)
mask = cv2.inRange(img, lower, upper)
res = cv2.bitwise_and(img,img, mask= mask)
obj.Proxy.img=res
def execute_HSV(proxy,obj):
say("hsv ..")
try: img=obj.sourceObject.Proxy.img.copy()
except: img=cv2.imread(__dir__+'/icons/freek.png')
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
lower=np.array([obj.valueColor-obj.deltaColor,0,0])
upper=np.array([obj.valueColor+obj.deltaColor,255,255])
mask = cv2.inRange(hsv, lower, upper)
res = cv2.bitwise_and(hsv,hsv, mask= mask)
obj.Proxy.img=res
def process_image(self, msg):
""" Process image messages from ROS and stash them in an attribute
called cv_image for subsequent processing """
self.cv_image = self.bridge.imgmsg_to_cv2(msg, desired_encoding="bgr8")
self.arc_image = np.zeros((480, 640, 3), np.uint8)
self.draw_arc()
# Transform the image of our arc from a top down image into the plane of our CV
self.transform_img()
# overlay the projected path onto cv_image
self.overlay_img()
if self.omega is not None and self.omega == 0.0:
self.hsv_image = cv2.cvtColor(self.cv_image, cv2.COLOR_BGR2HSV)
self.binary_image = cv2.inRange(self.hsv_image, self.hsv_lb, self.hsv_ub)
self.spot_delineators = self.find_delineators()
if self.color != (0, 255, 0): # This logic makes it such that once the lines turn green, they stay green
self.color = (0,0,255) if not self.check_aligned() else (0,255,0)
def extract_color( src, h_th_low, h_th_up, s_th, v_th ):
hsv = cv2.cvtColor(src, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
if h_th_low > h_th_up:
ret, h_dst_1 = cv2.threshold(h, h_th_low, 255, cv2.THRESH_BINARY)
ret, h_dst_2 = cv2.threshold(h, h_th_up, 255, cv2.THRESH_BINARY_INV)
dst = cv2.bitwise_or(h_dst_1, h_dst_2)
else:
ret, dst = cv2.threshold(h, h_th_low, 255, cv2.THRESH_TOZERO)
ret, dst = cv2.threshold(dst, h_th_up, 255, cv2.THRESH_TOZERO_INV)
ret, dst = cv2.threshold(dst, 0, 255, cv2.THRESH_BINARY)
ret, s_dst = cv2.threshold(s, s_th, 255, cv2.THRESH_BINARY)
ret, v_dst = cv2.threshold(v, v_th, 255, cv2.THRESH_BINARY)
dst = cv2.bitwise_and(dst, s_dst)
dst = cv2.bitwise_and(dst, v_dst)
return dst
calDepthMap.py 文件源码
项目:Color-Attenuation-Prior-Dehazing
作者: jevonswang
项目源码
文件源码
阅读 60
收藏 0
点赞 0
评论 0
def calDepthMap(I, r):
hsvI = cv2.cvtColor(I, cv2.COLOR_BGR2HSV)
s = hsvI[:,:,1] / 255.0
v = hsvI[:,:,2] / 255.0
#cv2.imshow("hsvI",hsvI)
#cv2.waitKey()
sigma = 0.041337
sigmaMat = np.random.normal(0, sigma, (I.shape[0], I.shape[1]))
output = 0.121779 + 0.959710 * v - 0.780245 * s + sigmaMat
outputPixel = output
output = scipy.ndimage.filters.minimum_filter(output,(r,r))
outputRegion = output
cv2.imwrite("data/vsFeature.jpg", outputRegion*255 )
#cv2.imshow("outputRegion",outputRegion)
#cv2.waitKey()
return outputRegion, outputPixel
runDehazing.py 文件源码
项目:Color-Attenuation-Prior-Dehazing
作者: jevonswang
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def calDepthMap(I, r):
#?????
hsvI = cv2.cvtColor(I, cv2.COLOR_BGR2HSV)
s = hsvI[:,:,1] / 255.0
v = hsvI[:,:,2] / 255.0
#cv2.imshow("hsvI",hsvI)
#cv2.waitKey()
sigma = 0.041337
sigmaMat = np.random.normal(0, sigma, (I.shape[0], I.shape[1]))
output = 0.121779 + 0.959710 * v - 0.780245 * s + sigmaMat
outputPixel = output
output = scipy.ndimage.filters.minimum_filter(output,(r,r))
outputRegion = output
cv2.imwrite("data/vsFeature.jpg", outputRegion*255 )
#cv2.imshow("outputRegion",outputRegion)
#cv2.waitKey()
return outputRegion, outputPixel
def draw_circle(event,x,y,flags,param):
#if event == cv2.EVENT_LBUTTONDBLCLK:
if event == cv2.EVENT_LBUTTONDOWN:
print ('mouse x and y is ')
print (x,y)
px = im1[y,x]
print ('RGB Value:')
print (px)
px_hsv = cv2.cvtColor(im1, cv2.COLOR_BGR2HSV)
H=px_hsv.item(y,x,0)
S=px_hsv.item(y,x,1)
V=px_hsv.item(y,x,2)
print ('HSV Value: H?S??V')
print (H,S,V)
def draw_circle(event,x,y,flags,param):
#if event == cv2.EVENT_LBUTTONDBLCLK:
if event == cv2.EVENT_LBUTTONDOWN:
print ('mouse x and y is ')
print (x,y)
px = im1[y,x]
print ('RGB Value:')
print px
px_hsv = cv2.cvtColor(im1, cv2.COLOR_BGR2HSV)
H=px_hsv.item(y,x,0)
S=px_hsv.item(y,x,1)
V=px_hsv.item(y,x,2)
print ('HSV Value: H?S??V')
print (H,S,V)
def _process_image(self, image):
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
hsv = cv2.medianBlur(hsv, 5)
draw_col = (0,0,255)
p1 = (self.edges['l'], self.edges['d'])
p2 = (self.edges['r'], self.edges['u'])
cv2.rectangle(hsv, p1, p2, draw_col)
vert_spacing = (self.edges['r'] - self.edges['l'])/float(len(grid))
for i in range(1, len(grid)):
x_pos = int(self.edges['l'] + i*vert_spacing)
p1 = (x_pos, self.edges['d'])
p2 = (x_pos, self.edges['u'])
cv2.line(hsv, p1, p2, draw_col)
horiz_spacing = (self.edges['d'] - self.edges['u'])/float(len(grid[0]))
for i in range(1, len(grid[0])):
y_pos = int(self.edges['u'] + i*horiz_spacing)
p1 = (self.edges['l'], y_pos)
p2 = (self.edges['r'], y_pos)
cv2.line(hsv, p1, p2, draw_col)
return hsv
def randomHueSaturationValue(image, hue_shift_limit=(-180, 180),
sat_shift_limit=(-255, 255),
val_shift_limit=(-255, 255), u=0.5):
if np.random.random() < u:
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(image)
hue_shift = np.random.uniform(hue_shift_limit[0], hue_shift_limit[1])
h = cv2.add(h, hue_shift)
sat_shift = np.random.uniform(sat_shift_limit[0], sat_shift_limit[1])
s = cv2.add(s, sat_shift)
val_shift = np.random.uniform(val_shift_limit[0], val_shift_limit[1])
v = cv2.add(v, val_shift)
image = cv2.merge((h, s, v))
image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)
return image
psuedo_label_dataset_generator.py 文件源码
项目:unet-tensorflow
作者: timctho
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def randomHueSaturationValue(image, hue_shift_limit=(-180, 180),
sat_shift_limit=(-255, 255),
val_shift_limit=(-255, 255), u=0.5):
if np.random.random() < u:
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(image)
hue_shift = np.random.uniform(hue_shift_limit[0], hue_shift_limit[1])
h = cv2.add(h, hue_shift)
sat_shift = np.random.uniform(sat_shift_limit[0], sat_shift_limit[1])
s = cv2.add(s, sat_shift)
val_shift = np.random.uniform(val_shift_limit[0], val_shift_limit[1])
v = cv2.add(v, val_shift)
image = cv2.merge((h, s, v))
image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)
return image
def color_mask(image, color, tolerance=0):
"""Extract a mask of image according to color under a certain
tolerance level (defaults to 0)."""
if tolerance > 100:
tolerance = 100
elif tolerance < 0:
tolerance = 0
tolerance = int(tolerance * 255 / 100)
red, green, blue = color
bgr_color = np.uint8([[[blue, green, red]]])
hsv_color = cv2.cvtColor(bgr_color, cv2.COLOR_BGR2HSV)[0][0]
mask_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
lower_range = hsv_color - np.array([tolerance, 0, 0])
lower_range[lower_range > 255] = 255
lower_range[lower_range < 0] = 0
upper_range = hsv_color + np.array([tolerance, 0, 0])
upper_range[upper_range > 255] = 255
upper_range[upper_range < 0] = 0
mask = cv2.inRange(mask_image, lower_range, upper_range)
return mask
def binary_thresh( img, boundaries, filter):
if filter == 'RGB':
frame_to_thresh = img.copy()
else:
frame_to_thresh = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
for (lower, upper) in boundaries:
# create numpy arrays from the boundaries
lower = np.array(lower, dtype = "uint8")
upper = np.array(upper, dtype = "uint8")
# find the colors within the specified boundaries and apply the mask
mask = cv2.inRange(frame_to_thresh, lower, upper)
output = cv2.bitwise_and(frame_to_thresh, frame_to_thresh, mask = mask) #Returns an RGB image
return mask
def load(self):
if self.path is None:
print "Current path is empty!"
print "Please set one!"
else:
try:
# Return a 3-channel color image
self.image = cv2.imread(self.path)
# cv2.imshow('f', self.image)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
except:
raise ValueError('Loading error!')
# convert RGB to HSV
self.hsv = cv2.cvtColor(self.image, cv2.COLOR_BGR2HSV)
# split image into HSV channels
self.h, self.s, self.v = cv2.split(self.hsv)
# Apply Gaussian noise and save
def blob__Detec(image):
img=copy(image)
height, width, channels = img.shape
new_img=np.ones((height,width,channels), np.uint8)
HSV = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
Yellow={'min':(20,100,100),'max':(30, 255, 255)}
Blue={'min':(50,100,100),'max':(100,255,255)}
Brown={'min':(0,100,0),'max':(20,255,255)}
mask_b=cv2.inRange(HSV,Blue['min'],Blue['max'])
mask_br=cv2.inRange(HSV,Brown['min'],Brown['max'])
mask_y=cv2.inRange(HSV,Yellow['min'],Yellow['max'])
blue=cv2.bitwise_and(img,img,mask=mask_b)
yellow=cv2.bitwise_and(img,img,mask=mask_y)
brown=cv2.bitwise_and(img,img,mask=mask_br)
new_img=cv2.add(blue,brown)
new_img=cv2.add(new_img,yellow)
return new_img
def hsvModer(self, index, hsv_valueT, hsv_value_B):
img_BGR = self.img[index]
img_RGB = cv2.cvtColor(img_BGR, cv2.COLOR_BGR2RGB)
img_HSV = cv2.cvtColor(img_BGR, cv2.COLOR_BGR2HSV)
lower_red = np.array(hsv_value_B)
upper_red = np.array(hsv_valueT)
mask = cv2.inRange(img_HSV, lower_red, upper_red)
res = cv2.bitwise_and(img_RGB, img_RGB, mask=mask)
if self.erosion:
kernel = np.ones((5, 5), np.uint8)
res = cv2.erode(res, kernel, iterations=1)
if self.dilate:
kernel = np.ones((9, 9), np.uint8)
res = cv2.dilate(res, kernel, iterations=1)
return res
arch_light_track.py 文件源码
项目:Vision_Processing-2016
作者: Sabercat-Robotics-4146-FRC
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def get_bounding_rect( cap, win_cap, win, upper, lower):
msk = cv2.dilate(cv2.erode( cv2.inRange( cv2.blur( cv2.cvtColor( cap, cv2.COLOR_BGR2HSV ), (5,5) ), np.array(lower), np.array(upper) ), None, iterations=3), None, iterations=3)
im2, contours, hierarchy = cv2.findContours( msk, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE )
if len(contours) > 0:
areas = [cv2.contourArea(c) for c in contours] # get the area of each contour
max_index = np.argmax(areas) # get the index of the largest contour by area
cnts = contours[max_index] # get the largest contout by area
cv2.drawContours(msk, [cnts], 0, (0,255,0), 3) # Draw the contours to the mask image
x,y,w,h = cv2.boundingRect(cnts) # get the bouding box information about the contour
cv2.rectangle(win_cap,(x,y),(x+w,y+h),(255,255,255),2) # Draw rectangle on the image to represent the bounding box
cv2.imshow( "debug.", win_cap )
try:
self.smt_dash.putNumber('vis_x', x)
self.smt_dash.putNumber('vis_y', y)
self.smt_dash.putNumber('vis_w', w)
self.smt_dash.putNumber('vis_h', h)
except Exception:
pass
def cb_pt(self, msg):
self.pt = int(msg.y), int(msg.x)
# print self.pt
if self.image is None:
print "NO IMAGE"
return
img = self.bridge.imgmsg_to_cv2(self.image)
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
vals = hsv_img[self.pt]
self.pts.append(vals)
pts = np.array(self.pts)
min_thresh = np.min(pts, axis=0).tolist()
max_thresh = np.max(pts, axis=0).tolist()
print "thresholds: %s, %s " %(min_thresh, max_thresh)
# rospy.init_node("huepicker")
def randomHueSaturationValue(image, hue_shift_limit=(-180, 180),
sat_shift_limit=(-255, 255),
val_shift_limit=(-255, 255), u=0.5):
if np.random.random() < u:
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(image)
hue_shift = np.random.uniform(hue_shift_limit[0], hue_shift_limit[1])
h = cv2.add(h, hue_shift)
sat_shift = np.random.uniform(sat_shift_limit[0], sat_shift_limit[1])
s = cv2.add(s, sat_shift)
val_shift = np.random.uniform(val_shift_limit[0], val_shift_limit[1])
v = cv2.add(v, val_shift)
image = cv2.merge((h, s, v))
image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)
return image
def randomHueSaturationValue(image, hue_shift_limit=(-180, 180),
sat_shift_limit=(-255, 255),
val_shift_limit=(-255, 255), u=0.5):
if np.random.random() < u:
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(image)
hue_shift = np.random.uniform(hue_shift_limit[0], hue_shift_limit[1])
h = cv2.add(h, hue_shift)
sat_shift = np.random.uniform(sat_shift_limit[0], sat_shift_limit[1])
s = cv2.add(s, sat_shift)
val_shift = np.random.uniform(val_shift_limit[0], val_shift_limit[1])
v = cv2.add(v, val_shift)
image = cv2.merge((h, s, v))
image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)
return image
def shoot(x1,y1,x2,y2, *args, **kwargs):
"""Takes screenshot at given coordinates as PIL image format, the converts to cv2 grayscale image format and returns it"""
# creates widht & height for screenshot region
w = x2 - x1
h = y2 - y1
# PIL format as RGB
img = pyautogui.screenshot(region=(x1,y1,w,h)) #X1,Y1,X2,Y2
#im.save('screenshot.png')
# Converts to an array used for OpenCV
img = np.array(img)
try:
for arg in args:
if arg == 'hsv':
# Converts to BGR format for OpenCV
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
return hsv_img
if arg == 'rgb':
rgb_img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
return rgb_img
except:
pass
cv_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
return cv_gray