当前位置: 首页>>代码示例>>Python>>正文


Python cv2.flip方法代码示例

本文整理汇总了Python中cv2.flip方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.flip方法的具体用法?Python cv2.flip怎么用?Python cv2.flip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv2的用法示例。


在下文中一共展示了cv2.flip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def main():
	capture = cv2.VideoCapture(0)
	_, image = capture.read()
	previous = image.copy()
	
	
	while (cv2.waitKey(1) < 0):
		_, image = capture.read()
		diff = cv2.absdiff(image, previous)
		#image = cv2.flip(image, 3)
		#image = cv2.norm(image)
		_, diff = cv2.threshold(diff, 32, 0, cv2.THRESH_TOZERO)
		_, diff = cv2.threshold(diff, 0, 255, cv2.THRESH_BINARY)
		
		diff = cv2.medianBlur(diff, 5)
		
		cv2.imshow('video', diff)
		previous = image.copy()
		
	capture.release()
	cv2.destroyAllWindows() 
开发者ID:petern3,项目名称:crop_row_detection,代码行数:23,代码来源:camera_test.py

示例2: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def main():
    cap = cv2.VideoCapture(0)
    face_recogniser = joblib.load(MODEL_PATH)
    preprocess = preprocessing.ExifOrientationNormalize()

    while True:
        # Capture frame-by-frame
        ret, frame = cap.read()
        frame = cv2.flip(frame, 1)

        img = Image.fromarray(frame)
        faces = face_recogniser(preprocess(img))
        if faces is not None:
            draw_bb_on_img(faces, img)

        # Display the resulting frame
        cv2.imshow('video', np.array(img))
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # When everything done, release the captureq
    cap.release()
    cv2.destroyAllWindows() 
开发者ID:arsfutura,项目名称:face-recognition,代码行数:25,代码来源:video_classifier.py

示例3: step

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def step(self, amt=1):
        image = self._capFrame()

        if self.crop:
            image = image[self._cropY + self.yoff:self._ih - self._cropY +
                          self.yoff, self._cropX + self.xoff:self._iw - self._cropX + self.xoff]
        else:
            t, b, l, r = self._pad
            image = cv2.copyMakeBorder(
                image, t, b, l, r, cv2.BORDER_CONSTANT, value=[0, 0, 0])

        resized = cv2.resize(image, (self.width, self.height),
                             interpolation=cv2.INTER_LINEAR)
        if self.mirror:
            resized = cv2.flip(resized, 1)

        for y in range(self.height):
            for x in range(self.width):
                self.layout.set(x, y, tuple(resized[y, x][0:3])) 
开发者ID:ManiacalLabs,项目名称:BiblioPixelAnimations,代码行数:21,代码来源:ScreenGrab.py

示例4: __next__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def __next__(self):
        self.count += 1

        # Respect FPS for files
        if self.isFile:
            delta = time.time() - self.ts
            self.sma.add(delta)
            time.sleep(max(0,(1.0 - self.sma.current*self.fps)/self.fps))
            self.ts = time.time()

        # Read image
        ret_val, img0 = self.cam.read()
        if not ret_val and self.isFile:
            self.cam.set(cv2.CAP_PROP_POS_FRAMES, 0)
            ret_val, img0 = self.cam.read()
        assert ret_val, 'Video Error'

        # Preprocess
        img = img0
        if not self.isFile:
            img = cv2.flip(img, 1)

        return self.count, img 
开发者ID:RedisGears,项目名称:EdgeRealtimeVideoAnalytics,代码行数:25,代码来源:capture.py

示例5: load_bin

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def load_bin(path, image_size):
  try:
    with open(path, 'rb') as f:
      bins, issame_list = pickle.load(f) #py2
  except UnicodeDecodeError as e:
    with open(path, 'rb') as f:
      bins, issame_list = pickle.load(f, encoding='bytes') #py3
  data_list = []
  for flip in [0,1]:
    data = nd.empty((len(issame_list)*2, 3, image_size[0], image_size[1]))
    data_list.append(data)
  for i in range(len(issame_list)*2):
    _bin = bins[i]
    img = mx.image.imdecode(_bin)
    if img.shape[1]!=image_size[0]:
      img = mx.image.resize_short(img, image_size[0])
    img = nd.transpose(img, axes=(2, 0, 1))
    for flip in [0,1]:
      if flip==1:
        img = mx.ndarray.flip(data=img, axis=2)
      data_list[flip][i][:] = img
    if i%1000==0:
      print('loading bin', i)
  print(data_list[0].shape)
  return (data_list, issame_list) 
开发者ID:deepinsight,项目名称:insightface,代码行数:27,代码来源:verification.py

示例6: load_bin

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def load_bin(path, image_size):
  bins, issame_list = pickle.load(open(path, 'rb'))
  data_list = []
  for flip in [0,1]:
    data = nd.empty((len(issame_list)*2, 3, image_size[0], image_size[1]))
    data_list.append(data)
  for i in xrange(len(issame_list)*2):
    _bin = bins[i]
    img = mx.image.imdecode(_bin)
    if img.shape[1]!=image_size[0]:
      img = mx.image.resize_short(img, image_size[0])
    img = nd.transpose(img, axes=(2, 0, 1))
    for flip in [0,1]:
      if flip==1:
        img = mx.ndarray.flip(data=img, axis=2)
      data_list[flip][i][:] = img
    if i%1000==0:
      print('loading bin', i)
  print(data_list[0].shape)
  return (data_list, issame_list) 
开发者ID:deepinsight,项目名称:insightface,代码行数:22,代码来源:verification.py

示例7: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def main():
    total_pics = 1000
    cap = cv2.VideoCapture(0)
    x, y, w, h = 300, 50, 350, 350

    pic_no = 0
    flag_start_capturing = False
    frames = 0

    while True:
        ret, frame = cap.read()
        frame = cv2.flip(frame, 1)
        #frame = cv2.resize(frame, (image_x, image_y))
        cv2.imwrite("hand_images/" + str(pic_no) + ".jpg", frame)
        cv2.imshow("Capturing gesture", frame)
        pic_no += 1
        if pic_no == total_pics:
            break 
开发者ID:akshaybahadur21,项目名称:Emojinator,代码行数:20,代码来源:get_hand_images.py

示例8: get_obj_patch

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def get_obj_patch(image_dir, obj, target_size = (224, 224)):
    ### Prepare image patch
    xmin = obj['xmin']  # + np.random.randint(-MAX_JIT, MAX_JIT+1)
    ymin = obj['ymin']  # + np.random.randint(-MAX_JIT, MAX_JIT+1)
    xmax = obj['xmax']  # + np.random.randint(-MAX_JIT, MAX_JIT+1)
    ymax = obj['ymax']  # + np.random.randint(-MAX_JIT, MAX_JIT+1)

    img = cv2.imread(image_dir + obj['image'])
    img = copy.deepcopy(img[ymin:ymax + 1, xmin:xmax + 1]).astype(np.float32)

    # flip the image
    flip = np.random.binomial(1, .5)
    is_flipped = False
    if flip > 0.5:
        img = cv2.flip(img, 1)
        is_flipped = True

    # resize the image to standard size
    img = cv2.resize(img, target_size)
    img = img - np.array([[[103.939, 116.779, 123.68]]])

    return img, is_flipped 
开发者ID:cersar,项目名称:3D_detection,代码行数:24,代码来源:process_data.py

示例9: __call__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def __call__(self, img, labelmap=None, maskmap=None):
        assert isinstance(img, np.ndarray)
        assert labelmap is None or isinstance(labelmap, np.ndarray)
        assert maskmap is None or isinstance(maskmap, np.ndarray)

        if random.random() > self.ratio:
            return img, labelmap, maskmap

        height, width, _ = img.shape
        img = cv2.flip(img, 1)
        if labelmap is not None:
            labelmap = cv2.flip(labelmap, 1)
            # to handle datasets with left/right annatations
            if self.swap_pair is not None:
                assert isinstance(self.swap_pair, (tuple, list))
                temp = labelmap.copy()
                for pair in self.swap_pair:
                    assert isinstance(pair, (tuple, list)) and len(pair) == 2
                    labelmap[temp == pair[0]] = pair[1]
                    labelmap[temp == pair[1]] = pair[0]

        if maskmap is not None:
            maskmap = cv2.flip(maskmap, 1)

        return img, labelmap, maskmap 
开发者ID:openseg-group,项目名称:openseg.pytorch,代码行数:27,代码来源:cv2_aug_transforms.py

示例10: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def __init__(self, **kwargs):
        global cap, frame, frame_size

        # capture and render the first frame
        self.frame_size = frame_size
        frame = cap.read()
        image = cv2.flip(frame, 0)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        image = cv2.resize(image, frame_size)
        buf = image.tostring()
        self.image_texture = Texture.create(size=(image.shape[1], image.shape[0]), colorfmt='rgb')
        self.image_texture.blit_buffer(buf, colorfmt='rgb', bufferfmt='ubyte')

        # coordinates of Trashy
        self.t_x = 0
        self.t_y = 0

        self.current_user = 'No user yet'
        self.tickcount = 0
        self.labels = ["can", "bottle", "ken",
                       "grace", "frank", "tim", "shelly"]
        self.users = ["ken", "grace", "frank", "tim", "shelly"]

        super(MainView, self).__init__(**kwargs)
        Clock.schedule_interval(self.tick, 0.06) 
开发者ID:tlkh,项目名称:SmartBin,代码行数:27,代码来源:SmartBinApp.py

示例11: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def main(directory, name, test):
    cap = cv2.VideoCapture(0)

    i = 0
    while True:
        # Capture frame-by-frame
        ret, frame = cap.read()
        frame = cv2.flip(frame, 1)

        # Display the resulting frame
        cv2.imshow(name, frame)
        if not test and i != 0 and i % 10 == 0:
            cv2.imwrite("{}/{}{}.png".format(directory, name, int(i / 10)), frame)
        i += 1
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # When everything done, release the captureq
    cap.release()
    cv2.destroyAllWindows() 
开发者ID:arsfutura,项目名称:face-recognition,代码行数:22,代码来源:collect_face_images.py

示例12: rotate

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def rotate(img, angle=90, clockwise=True):
    """
        函数使图片可顺时针或逆时针旋转90、180、270度.
        默认clockwise=True:顺时针旋转
    """

    def count_clock_rotate(img):
        # 逆时针旋转90°
        rows, cols = img.shape[:2]
        rotate_img = np.zeros((cols, rows))
        rotate_img = cv2.transpose(img)
        rotate_img = cv2.flip(rotate_img, 0)
        return rotate_img

    # 将角度旋转转化为逆时针旋转90°的次数:
    counter_rotate_time = (4 - angle / 90) % 4 if clockwise else (angle / 90) % 4
    for i in range(int(counter_rotate_time)):
        img = count_clock_rotate(img)

    return img 
开发者ID:AirtestProject,项目名称:Airtest,代码行数:22,代码来源:aircv.py

示例13: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def __init__(self, horiz=False, vert=False, prob=0.5):
        """
        Only one of horiz, vert can be set.

        :param horiz: whether or not apply horizontal flip.
        :param vert: whether or not apply vertical flip.
        :param prob: probability of flip.
        """
        super(Flip, self).__init__()
        if horiz and vert:
            raise ValueError("Please use two Flip instead.")
        elif horiz:
            self.code = 1
        elif vert:
            self.code = 0
        else:
            raise ValueError("Are you kidding?")
        self.prob = prob
        self._init() 
开发者ID:anonymous-author1,项目名称:DDRL,代码行数:21,代码来源:noname.py

示例14: Mirror

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def Mirror(src,label=None,symmetry=None):

    img = cv2.flip(src, 1)
    if label is None:
        return img,label

    width=img.shape[1]
    cod = []
    allc = []
    for i in range(label.shape[0]):
        x, y = label[i][0], label[i][1]
        if x >= 0:
            x = width - 1 - x
        cod.append((x, y))
    # **** the joint index depends on the dataset ****
    for (q, w) in symmetry:
        cod[q], cod[w] = cod[w], cod[q]
    for i in range(label.shape[0]):
        allc.append(cod[i][0])
        allc.append(cod[i][1])
    label = np.array(allc).reshape(label.shape[0], 2)
    return img,label 
开发者ID:610265158,项目名称:face_landmark,代码行数:24,代码来源:augmentation.py

示例15: augment

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import flip [as 别名]
def augment(self, Xb):
        # Random number 0-1 whether we flip or not
        random_flip = np.random.randint(2) == 1

        # Translation shift
        shift_x = np.random.uniform(*params.AUGMENTATION_PARAMS['translation_range'])
        shift_y = np.random.uniform(*params.AUGMENTATION_PARAMS['translation_range'])

        # Rotation, zoom
        rotation = np.random.uniform(*params.AUGMENTATION_PARAMS['rotation_range'])
        log_zoom_range = [np.log(z) for z in params.AUGMENTATION_PARAMS['zoom_range']]
        zoom = np.exp(np.random.uniform(*log_zoom_range))

        # Color AUGMENTATION_PARAMS
        random_hue = np.random.uniform(*params.AUGMENTATION_PARAMS['hue_range'])
        random_saturation = np.random.uniform(*params.AUGMENTATION_PARAMS['saturation_range'])
        random_value = np.random.uniform(*params.AUGMENTATION_PARAMS['value_range'])

        return self.augment_with_params(Xb, shift_x, shift_y, rotation, random_flip, zoom, random_hue, random_saturation, random_value) 
开发者ID:gzuidhof,项目名称:luna16,代码行数:21,代码来源:augment.py


注:本文中的cv2.flip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。