我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用cv2.COLOR_RGB2YUV。
def get_color_medio(self, roi, a,b,imprimir = False): xl,yl,ch = roi.shape roiyuv = cv2.cvtColor(roi,cv2.COLOR_RGB2YUV) roihsv = cv2.cvtColor(roi,cv2.COLOR_RGB2HSV) h,s,v=cv2.split(roihsv) mask=(h<5) h[mask]=200 roihsv = cv2.merge((h,s,v)) std = np.std(roiyuv.reshape(xl*yl,3),axis=0) media = np.mean(roihsv.reshape(xl*yl,3), axis=0)-60 mediayuv = np.mean(roiyuv.reshape(xl*yl,3), axis=0) if std[0]<12 and std[1]<12 and std[2]<12: #if (std[0]<15 and std[2]<15) or ((media[0]>100 or media[0]<25) and (std[0]>10)): media = np.mean(roihsv.reshape(xl*yl,3), axis=0) # el amarillo tiene 65 de saturacion y sobre 200 if media[1]<60: #and (abs(media[0]-30)>10): # blanco return [-10,0,0] else: return media else: return None
def yuvPassShadowRemoval(src, shadowThreshold): height, width = src.shape[:2] imgYUV = cv2.cvtColor(src, cv2.COLOR_RGB2YUV) yImg, uImg, vImg = cv2.split(imgYUV) # for i in range(0, height): # for j in range(0, width): # yImg[i, j] = 0 yImg = np.zeros((height, width, 1), np.uint8) imgYUV = cv2.merge([yImg, uImg, vImg]) rgbImg = cv2.cvtColor(imgYUV, cv2.COLOR_YUV2RGB) rImg, gImg, bImg = cv2.split(rgbImg) count = width * height avg = np.sum(bImg) avg /= count * 1.0 # for i in range(0, height): # for j in range(0, width): # if bImg[i, j] > ave: # rImg[i, j] = 255 # gImg[i, j] = 255 # bImg[i, j] = 255 # else: # rImg[i, j] = 0 # gImg[i, j] = 0 # bImg[i, j] = 0 if shadowThreshold is None: avg = avg else: avg = shadowThreshold np.where(bImg > avg, 255, 0) _, threshold = cv2.threshold(bImg, avg, 255, cv2.THRESH_BINARY) output = threshold return output
def rgb2yuv(image): """ Convert the image from RGB to YUV (This is what the NVIDIA model does) """ return cv2.cvtColor(image, cv2.COLOR_RGB2YUV)
def load_image(path): img = skimage.io.imread(path) yuv = cv2.cvtColor(np.float32(img), cv2.COLOR_RGB2YUV) img = img - vgg19.VGG_MEAN img = img[:,:,(2,1,0)] # rgb to bgr return img[np.newaxis, :, :, :], yuv
def save_image(img, path, content_yuv=None): img = np.squeeze(img) img = img[:,:,(2,1,0)] # bgr to rgb img = img + vgg19.VGG_MEAN if content_yuv is not None: yuv = cv2.cvtColor(np.float32(img), cv2.COLOR_RGB2YUV) yuv[:,:,1:3] = content_yuv[:,:,1:3] img = cv2.cvtColor(yuv, cv2.COLOR_YUV2RGB) img = np.clip(img, 0, 255).astype(np.uint8) skimage.io.imsave(path, img)
def predict_steering(self, data): image_array = self.roi(cv2.cvtColor(data['image'], cv2.COLOR_RGB2YUV)) transformed_image_array = image_array[None, :, :, :] return float(model.predict(transformed_image_array, batch_size=1)) # Callback functions triggered by ControlServer
def preprocess_input(self, img): return self.roi(cv2.cvtColor(img, cv2.COLOR_RGB2YUV))
def preprocess_input(img): return roi(cv2.cvtColor(img, cv2.COLOR_RGB2YUV))
def preprocess_image(image): image = cv2.resize(image, (0,0), fx=fx, fy=fy) image = cv2.cvtColor(image, cv2.COLOR_RGB2YUV) # Normalize image = (image - 128.)/255. return image
def convert2YUV(img): return cv2.cvtColor(img, cv2.COLOR_RGB2YUV)
def extract_features(imgs, color_space='RGB', spatial_size=(32, 32), hist_bins=32, orient=9, pix_per_cell=8, cell_per_block=2, hog_channel=0, spatial_feat=True, hist_feat=True, hog_feat=True): # Create a list to append feature vectors to features = [] # Iterate through the list of images for file in imgs: file_features = [] # Read in each one by one image = mpimg.imread(file) # apply color conversion if other than 'RGB' if color_space != 'RGB': if color_space == 'HSV': feature_image = cv2.cvtColor(image, cv2.COLOR_RGB2HSV) elif color_space == 'LUV': feature_image = cv2.cvtColor(image, cv2.COLOR_RGB2LUV) elif color_space == 'HLS': feature_image = cv2.cvtColor(image, cv2.COLOR_RGB2HLS) elif color_space == 'YUV': feature_image = cv2.cvtColor(image, cv2.COLOR_RGB2YUV) elif color_space == 'YCrCb': feature_image = cv2.cvtColor(image, cv2.COLOR_RGB2YCrCb) else: feature_image = np.copy(image) if spatial_feat == True: spatial_features = bin_spatial(feature_image, size=spatial_size) file_features.append(spatial_features) if hist_feat == True: # Apply color_hist() hist_features = color_hist(feature_image, nbins=hist_bins) file_features.append(hist_features) if hog_feat == True: # Call get_hog_features() with vis=False, feature_vec=True if hog_channel == 'ALL': hog_features = [] for channel in range(feature_image.shape[2]): hog_features.append(get_hog_features(feature_image[:,:,channel], orient, pix_per_cell, cell_per_block, vis=False, feature_vec=True)) hog_features = np.ravel(hog_features) else: hog_features = get_hog_features(feature_image[:,:,hog_channel], orient, pix_per_cell, cell_per_block, vis=False, feature_vec=True) # Append the new feature vector to the features list file_features.append(hog_features) features.append(np.concatenate(file_features)) # Return list of feature vectors return features # Define a function that takes an image, # start and stop positions in both x and y, # window size (x and y dimensions), # and overlap fraction (for both x and y)
def single_img_features(img, color_space='RGB', spatial_size=(32, 32), hist_bins=32, hist_range=(0, 256), orient=9, pix_per_cell=8, cell_per_block=2, hog_channel=0, spatial_feat=True, hist_feat=True, hog_feat=True): img_features = [] # apply color conversion if other than 'RGB' if color_space != 'RGB': if color_space == 'HSV': feature_image = cv2.cvtColor(img, cv2.COLOR_RGB2HSV) elif color_space == 'LUV': feature_image = cv2.cvtColor(img, cv2.COLOR_RGB2LUV) elif color_space == 'HLS': feature_image = cv2.cvtColor(img, cv2.COLOR_RGB2HLS) elif color_space == 'YUV': feature_image = cv2.cvtColor(img, cv2.COLOR_RGB2YUV) elif color_space == 'YCrCb': feature_image = cv2.cvtColor(img, cv2.COLOR_RGB2YCrCb) else: feature_image = np.copy(img) if spatial_feat == True: spatial_features = bin_spatial(feature_image, size=spatial_size) img_features.append(spatial_features) if hist_feat == True: # Apply color_hist() hist_features = color_hist(feature_image, nbins=hist_bins, bins_range=hist_range) img_features.append(hist_features) if hog_feat == True: # Call get_hog_features() with vis=False, feature_vec=True if hog_channel == 'ALL': hog_features = [] for channel in range(feature_image.shape[2]): hog_features.extend(get_hog_features(feature_image[:,:,channel], orient, pix_per_cell, cell_per_block, vis=False, feature_vec=True)) else: hog_features = get_hog_features(feature_image[:,:,hog_channel], orient, pix_per_cell, cell_per_block, vis=False, feature_vec=True) # Append the new feature vector to the features list img_features.append(hog_features) # Return list of feature vectors return np.concatenate(img_features) # Convert windows to heatmap numpy array.