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


Python imutils.resize方法代码示例

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


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

示例1: start

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def start(self):
        """
        启动程序
        :return:
        """
        self.console("程序启动成功.")
        self.init_mask()
        while self.listener:
            frame = self.read_data()
            frame = resize(frame, width=self.max_width)
            img_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            rects = self.detector(img_gray, 0)
            faces = self.orientation(rects, img_gray)
            draw_img = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
            if self.doing:
                self.drawing(draw_img, faces)
                self.animation_time += self.speed
                self.save_data(draw_img)
                if self.animation_time > self.duration:
                    self.doing = False
                    self.animation_time = 0
                else:
                    frame = cv2.cvtColor(np.asarray(draw_img), cv2.COLOR_RGB2BGR)
            cv2.imshow("hello mask", frame)
            self.listener_keys() 
开发者ID:tomoncle,项目名称:face-detection-induction-course,代码行数:27,代码来源:input_video_stream_paste_mask.py

示例2: align_face

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def align_face(img):
    img = img[:, :, ::-1]  # Convert from RGB to BGR format
    img = imutils.resize(img, width=800)

    # detect faces in the grayscale image
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    rects = detector(gray, 2)

    if len(rects) > 0:
        # align the face using facial landmarks
        align_img = fa.align(img, gray, rects[0])[:, :, ::-1]
        align_img = np.array(Image.fromarray(align_img).convert('RGB'))
        return align_img, True
    else:
        # No face found
        return None, False

# Input: img_path
# Output: aligned_img if face_found, else None 
开发者ID:openai,项目名称:glow,代码行数:21,代码来源:align_face.py

示例3: start_capture

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def start_capture(self, height=None, width=None, usingPiCamera=IS_RASPBERRY_PI, ):
        import imutils
        from imutils.video import VideoStream
        resolution = (self.height, self.width)
        if height:
            if width:
                resolution = (height, width)
        print("Camera Resolution:", resolution)
        cf = VideoStream(usePiCamera=usingPiCamera,
                         resolution=resolution,
                         framerate=30).start()
        self.current_frame = cf
        time.sleep(2)

        if not usingPiCamera:
            frame = imutils.resize(self.current_frame.read(), width=resolution[0], height=resolution[1])
        # Stream started, call current_frame.read() to get current frame 
开发者ID:CT83,项目名称:Facial-Recognition-Attendance-System,代码行数:19,代码来源:Camera.py

示例4: preprocess

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def preprocess(self, image: np.ndarray) -> np.ndarray:
        (h, w) = image.shape[:2]
        dW = 0
        dH = 0

        if w < h:
            image = imutils.resize(image, width=self.width, inter=self.inter)
            dH = int((image.shape[0] - self.height) / 2.0)
        else:
            image = imutils.resize(image, height=self.height, inter=self.inter)
            dW = int((image.shape[1] - self.width) / 2.0)

        (h, w) = image.shape[:2]
        image = image[dH : h - dH, dW : w - dW]

        return cv2.resize(image, (self.width, self.height), interpolation=self.inter) 
开发者ID:jrzaurin,项目名称:pytorch-widedeep,代码行数:18,代码来源:image_utils.py

示例5: getLicensePlateNumber

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def getLicensePlateNumber(filer):
	try:
		js = api.recognize_file(filer, secret_key, country, recognize_vehicle=recognize_vehicle, state=state, return_image=return_image, topn=topn, prewarp=prewarp)

		js=js.to_dict()
		#js=list(str(js))
		X1=js['results'][0]['coordinates'][0]['x']
		Y1=js['results'][0]['coordinates'][0]['y']
		X2=js['results'][0]['coordinates'][2]['x']
		Y2=js['results'][0]['coordinates'][2]['y']
		img=cv2.imread(filer)
		rimg=img[Y1:Y2,X1:X2]
		frame3=rimg
		img3 = Image.fromarray(frame3)
		w,h=img3.size
		asprto=w/h
		frame3=cv2.resize(frame3,(150,int(150/asprto)))
		cv2image3 = cv2.cvtColor(frame3, cv2.COLOR_BGR2RGBA)
		img3 = Image.fromarray(cv2image3)
		imgtk3 = ImageTk.PhotoImage(image=img3)
		display4.imgtk = imgtk3 #Shows frame for display 1
		display4.configure(image=imgtk3)
		display5.configure(text=js['results'][0]['plate'])
	except ApiException as e:
	    print("Exception: \n", e) 
开发者ID:ShreyAmbesh,项目名称:Traffic-Rule-Violation-Detection-System,代码行数:27,代码来源:VehicleMoniter.py

示例6: _resize_frame

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def _resize_frame(self, frame):
        if self._processing_resize_kwargs == {}:
            if self.processing_max_dim:
                shape = frame.shape
                max_dim_size = max(shape)

                if max_dim_size <= self.processing_max_dim:
                    self.processing_max_dim = max_dim_size
                    self._processing_resize_kwargs = None
                else:
                    max_dim_ind = shape.index(max_dim_size)
                    max_dim_name = ['height', 'width'][max_dim_ind]
                    self._processing_resize_kwargs = {max_dim_name: self.processing_max_dim}

        if self._processing_resize_kwargs is None:
            return frame

        resized = imutils.resize(frame, **self._processing_resize_kwargs)
        return resized 
开发者ID:AdamSpannbauer,项目名称:python_video_stab,代码行数:21,代码来源:VidStab.py

示例7: resizeToMainWindowSize

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def resizeToMainWindowSize ( image, winSize ):
    '''
        ==================================================
        Resize the window size for larger than given image
        ==================================================  

        Arguments:
            image: Image you want to resize
            winSize: Window size of the image
        Returns:
            Resize image of given window size 
    '''
    if type (winSize) == int:
        return cv2.resize (image, (winSize, winSize), interpolation=cv2.INTER_CUBIC)
    elif type (winSize) == []:
        return cv2.resize (image, (winSize[0], winSize[1]), interpolation=cv2.INTER_CUBIC)
    elif type (winSize) == ():
        return cv2.resize (image, (winSize), interpolation=cv2.INTER_CUBIC) 
开发者ID:nabulago,项目名称:anomaly-event-detection,代码行数:20,代码来源:mylib.py

示例8: preprocess

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def preprocess(image, width, height):
    # Grab the dimensions of the image, then initialize the padding values
    (h, w) = image.shape[:2]

    # If the width is greater than the height then resize along the width
    if w > h:
        image = imutils.resize(image, width=width)
    # Otherwise, the height is greater than the width so resize along the height
    else:
        image = imutils.resize(image, height=height)

    # Determine the padding values for the width and height to obtain the target dimensions
    pad_w = int((width - image.shape[1]) / 2.0)
    pad_h = int((height - image.shape[0]) / 2.0)

    # Pad the image then apply one more resizing to handle any rounding issues
    image = cv2.copyMakeBorder(image, pad_h, pad_h, pad_w, pad_w, cv2.BORDER_REPLICATE)
    image = cv2.resize(image, (width, height))

    # Return the pre-processed image
    return image 
开发者ID:Abhs9,项目名称:DL4CVStarterBundle,代码行数:23,代码来源:captchahelper.py

示例9: preprocess

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def preprocess(self, image):
    # grab the dimensions of the image and then initialize
    # the deltas to use when cropping
    (h, w) = image.shape[:2]
    dW = 0
    dH = 0
    # if the width is smaller than the height, then resize
    # along the width (i.e., the smaller dimension) and then update
    # the deltas to crop the height to the desired dimension
    if w < h:
      image = imutils.resize(image, width=self.width, inter=self.inter)
      dH = int((image.shape[0] - self.height) / 2.0)
    else:
      image = imutils.resize(image, height=self.height, inter=self.inter)
      dW = int((image.shape[1] - self.width) / 2.0)

    # now that our images have ben resized, we need to re-grab the width
    # and height, followed by performing the crop
    (h, w) = image.shape[:2]
    image = image[dH:h-dH, dW:w-dW]
    return cv2.resize(image, (self.width, self.height), interpolation=self.inter) 
开发者ID:mogoweb,项目名称:aiexamples,代码行数:23,代码来源:aspectawarepreprocessor.py

示例10: preprocess

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def preprocess(self, image):
        '''
        grab the dimentions of the image and then initialize the deltas to use when cropping
        '''
        (h, w) = image.shape[:2]
        dW = 0
        dH = 0

        # if the width is smaller than the height, then resize along the width and then update the daltas to crop the height to the desired dimension
        if w < h:
            image = imutils.resize(image, width=self.width, inter=self.inter)
            dH = int((image.shape[0] - self.height) / 2.0)

        # otherwise the height is smaller than the width so resize along the height and then update the deltas to crop along the width
        else:
            image = imutils.resize(image, height=self.height, inter=self.inter)
            dW = int((image.shape[1] - self.width) / 2.0)

        # now that our image have been resized, we need to re-grab the width and height, followed by performing the crop
        (h, w) = image.shape[:2]
        image = image[dH:h - dH, dW:w - dW]

        # finally, resize the image to the provided spatial dimentions to ensure our output image is always a fixed size
        return cv2.resize(image, (self.width, self.height), interpolation=self.inter) 
开发者ID:Sid2697,项目名称:Smile-Detector,代码行数:26,代码来源:aspectawarepreprocessor.py

示例11: detect

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def detect(self):
        vframe = None
        while vframe is None:
            vframe = self.cap.read()

        image = vframe.get_bgr()

        # Reference: https://www.pyimagesearch.com/2015/11/09/pedestrian-detection-opencv/

        # resize for (1) reducting run time, (2) improving accuracy
        imutils.resize(image, width=min(400, image.shape[1]))
        (rects, weights) = self.hog.detectMultiScale(
            image, winStride=(4, 4), padding=(8, 8), scale=1.05
        )

        # apply non-maxima suppression to the bounding boxes
        rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects])
        pick = non_max_suppression(rects, probs=None, overlapThresh=0.65)

        for (xA, yA, xB, yB) in pick:
            cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2)

        scorer.imshow(1, image)

        return len(pick), int(time.mktime(vframe.datetime.timetuple())) 
开发者ID:treasure-data,项目名称:treasure-boxes,代码行数:27,代码来源:pedestrian_detector.py

示例12: start_capture

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def start_capture(self, height=None, width=None, usingPiCamera=IS_RASPBERRY_PI, ):
        import imutils
        from imutils.video import VideoStream
        resolution = (self.height, self.width)
        if height:
            if width:
                resolution = (height, width)
        cf = VideoStream(usePiCamera=usingPiCamera,
                         resolution=resolution,
                         framerate=32).start()
        self.current_frame = cf
        time.sleep(2)

        if not usingPiCamera:
            frame = imutils.resize(self.current_frame.read(), width=resolution[0])
        # Stream started, call current_frame.read() to get current frame 
开发者ID:CT83,项目名称:SmoothStream,代码行数:18,代码来源:Camera.py

示例13: getscale

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def getscale(self):
        if g.config['resize'] != 'no':
            img = cv2.imread(self.filename)
            img_new = imutils.resize(img,
                                     width=min(int(g.config['resize']),
                                               img.shape[1]))
            oldh, oldw, _ = img.shape
            newh, neww, _ = img_new.shape
            rescale = True
            xfactor = neww / oldw
            yfactor = newh / oldh
            img = None
            img_new = None
            g.logger.debug(
                'ALPR will use {}x{} but Yolo uses {}x{} so ALPR boxes will be scaled {}x and {}y'
                .format(oldw, oldh, neww, newh, xfactor, yfactor),level=2)
        else:
            xfactor = 1
            yfactor = 1
        return (xfactor, yfactor) 
开发者ID:dlandon,项目名称:zoneminder,代码行数:22,代码来源:alpr.py

示例14: mainLoop

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def mainLoop(self):
        frame = self.webcam.get_frame()
        f1 = imutils.resize(frame, width = 256)
        #crop_frame = frame[100:228,200:328]
        self.data_buffer.append(f1)
        self.run_color()
        #print(frame)
        
        #if len(self.vidmag_frames) > 0:
            #print(self.vidmag_frames[0])
        cv2.putText(frame, "FPS "+str(float("{:.2f}".format(self.fps))),
                       (20,420), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 255, 0),2)
            
        #frame[100:228,200:328] = cv2.convertScaleAbs(self.vidmag_frames[-1])
        cv2.imshow("Original",frame)
        #f2 = imutils.resize(cv2.convertScaleAbs(self.vidmag_frames[-1]), width = 640)
        f2 = imutils.resize(cv2.convertScaleAbs(self.frame_out), width = 640)
            
        cv2.imshow("Color amplification",f2)
            
            
        self.key_handler()  #if not the GUI cant show anything 
开发者ID:habom2310,项目名称:Heart-rate-measurement-using-camera,代码行数:24,代码来源:amplify_color.py

示例15: preprocessInputFrame

# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import resize [as 别名]
def preprocessInputFrame(self, newFrame):
        if self.resizeBeforeDetect:
            return imutils.resize(newFrame, width=500, height=500)

        return newFrame.copy() 
开发者ID:JFF-Bohdan,项目名称:pynvr,代码行数:7,代码来源:motion_detection.py


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