當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.cartToPolar方法代碼示例

本文整理匯總了Python中cv2.cartToPolar方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.cartToPolar方法的具體用法?Python cv2.cartToPolar怎麽用?Python cv2.cartToPolar使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cv2的用法示例。


在下文中一共展示了cv2.cartToPolar方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: preprocess_hog

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def preprocess_hog(digits):
	samples = []
	for img in digits:
		gx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
		gy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
		mag, ang = cv2.cartToPolar(gx, gy)
		bin_n = 16
		bin = np.int32(bin_n*ang/(2*np.pi))
		bin_cells = bin[:10,:10], bin[10:,:10], bin[:10,10:], bin[10:,10:]
		mag_cells = mag[:10,:10], mag[10:,:10], mag[:10,10:], mag[10:,10:]
		hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
		hist = np.hstack(hists)
		
		# transform to Hellinger kernel
		eps = 1e-7
		hist /= hist.sum() + eps
		hist = np.sqrt(hist)
		hist /= norm(hist) + eps
		
		samples.append(hist)
	return np.float32(samples)
#不能保證包括所有省份 
開發者ID:wzh191920,項目名稱:License-Plate-Recognition,代碼行數:24,代碼來源:predict.py

示例2: preprocess_hog

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def preprocess_hog(digits):
	samples = []
	for img in digits:
		gx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
		gy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
		mag, ang = cv2.cartToPolar(gx, gy)
		bin_n = 16
		bin = np.int32(bin_n*ang/(2*np.pi))
		bin_cells = bin[:10,:10], bin[10:,:10], bin[:10,10:], bin[10:,10:]
		mag_cells = mag[:10,:10], mag[10:,:10], mag[:10,10:], mag[10:,10:]
		hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
		hist = np.hstack(hists)
		
		# transform to Hellinger kernel
		eps = 1e-7
		hist /= hist.sum() + eps
		hist = np.sqrt(hist)
		hist /= norm(hist) + eps
		
		samples.append(hist)
	return np.float32(samples) 
開發者ID:DataXujing,項目名稱:vehicle-license-plate-recognition,代碼行數:23,代碼來源:svm_train.py

示例3: proc_oflow

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def proc_oflow(images):
  h, w = images.shape[-3:-1]

  processed_images = []
  for image in images:
    hsv = np.zeros((h, w, 3), dtype=np.uint8)
    hsv[:, :, 0] = 255
    hsv[:, :, 1] = 255

    mag, ang = cv2.cartToPolar(image[..., 0], image[..., 1])
    hsv[..., 0] = ang*180/np.pi/2
    hsv[..., 2] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX)

    processed_image = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
    processed_images.append(processed_image)

  return np.stack(processed_images) 
開發者ID:google,項目名稱:graph_distillation,代碼行數:19,代碼來源:imgproc.py

示例4: preprocess_hog

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def preprocess_hog(digits):
    samples = []
    for img in digits:
        gx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
        gy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
        mag, ang = cv2.cartToPolar(gx, gy)
        bin_n = 16
        bin = np.int32(bin_n*ang/(2*np.pi))
        bin_cells = bin[:10,:10], bin[10:,:10], bin[:10,10:], bin[10:,10:]
        mag_cells = mag[:10,:10], mag[10:,:10], mag[:10,10:], mag[10:,10:]
        hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
        hist = np.hstack(hists)

        # transform to Hellinger kernel
        eps = 1e-7
        hist /= hist.sum() + eps
        hist = np.sqrt(hist)
        hist /= norm(hist) + eps

        samples.append(hist)
    return np.float32(samples) 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:23,代碼來源:digits.py

示例5: compute_dense_optical_flow

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def compute_dense_optical_flow(prev_image, current_image):
  old_shape = current_image.shape
  prev_image_gray = cv2.cvtColor(prev_image, cv2.COLOR_BGR2GRAY)
  current_image_gray = cv2.cvtColor(current_image, cv2.COLOR_BGR2GRAY)
  assert current_image.shape == old_shape
  hsv = np.zeros_like(prev_image)
  hsv[..., 1] = 255
  flow = None
  flow = cv2.calcOpticalFlowFarneback(prev=prev_image_gray,
                                      next=current_image_gray, flow=flow,
                                      pyr_scale=0.8, levels=15, winsize=5,
                                      iterations=10, poly_n=5, poly_sigma=0,
                                      flags=10)

  mag, ang = cv2.cartToPolar(flow[..., 0], flow[..., 1])
  hsv[..., 0] = ang * 180 / np.pi / 2
  hsv[..., 2] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX)
  return cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR) 
開發者ID:ferreirafabio,項目名稱:video2tfrecord,代碼行數:20,代碼來源:video2tfrecord.py

示例6: _make_block_hofm

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def _make_block_hofm(flow, blocks, mag_buckets, ang_buckets, skutil):
    mag, ang = cartToPolar(flow[..., 0], flow[..., 1], angleInDegrees=True)

    mag_digit = digitize(mag, mag_buckets)
    # mod so 360 falls into first bucket
    ang_digit = digitize(ang % 360, ang_buckets)

    mag_blocks = skutil.view_as_blocks(mag_digit, (blocks, blocks))
    ang_blocks = skutil.view_as_blocks(ang_digit, (blocks, blocks))

    histogram = zeros(
        (blocks, blocks, len(mag_buckets), len(ang_buckets) - 1)
    )

    for i in range(blocks):
        for j in range(blocks):
            for mblock, ablock in zip(
                mag_blocks[:, :, i, j].flatten(),
                ang_blocks[:, :, i, j].flatten(),
            ):
                histogram[i, j, mblock - 1, ablock - 1] += 1
        # normalize by block size (h,w)
        histogram[i, j, :, :] /= mag_blocks[:, :, i, j].size
    return histogram 
開發者ID:distant-viewing,項目名稱:dvt,代碼行數:26,代碼來源:hofm.py

示例7: get_mag_ang

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def get_mag_ang(img):

    """
    Gets image gradient (magnitude) and orientation (angle)

    Args:
        img

    Returns:
        Gradient, orientation
    """

    img = np.sqrt(img)

    gx = cv2.Sobel(np.float32(img), cv2.CV_32F, 1, 0)
    gy = cv2.Sobel(np.float32(img), cv2.CV_32F, 0, 1)

    mag, ang = cv2.cartToPolar(gx, gy)

    return mag, ang, gx, gy 
開發者ID:jgrss,項目名稱:spfeas,代碼行數:22,代碼來源:spfunctions.py

示例8: flow2colorimage

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def flow2colorimage(ar_f_Flow:np.array(float)) -> np.array(int):
    """ translate 1 optical flow (with values from -1.0 to 1.0) to an colorful image
    """

    h, w, c = ar_f_Flow.shape
    if not isinstance(ar_f_Flow[0,0,0], np.float32): 
        warnings.warn("Need to convert flows to float32")
        ar_f_Flow = ar_f_Flow.astype(np.float32)

    ar_n_hsv = np.zeros((h, w, 3), dtype = np.uint8)
    ar_n_hsv[...,1] = 255

    # get colors
    mag, ang = cv2.cartToPolar(ar_f_Flow[..., 0], ar_f_Flow[..., 1])
    ar_n_hsv[...,0] = ang * 180 / np.pi / 2
    ar_n_hsv[...,2] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX)

    ar_n_bgr = cv2.cvtColor(ar_n_hsv, cv2.COLOR_HSV2BGR)
    return ar_n_bgr 
開發者ID:FrederikSchorr,項目名稱:sign-language,代碼行數:21,代碼來源:opticalflow.py

示例9: flow_to_rgb

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def flow_to_rgb(flow):
    """
    Visualizes optical flow in hsv space and converts it to rgb space.
    :param flow: (np.array (h, w, c)) optical flow
    :return: (np.array (h, w, c)) rgb data
    """
    im1 = flow[:, :, 0]
    im2 = flow[:, :, 1]

    h, w = flow.shape[:2]

    # Use Hue, Saturation, Value colour model
    hsv = np.zeros((h, w, 3), dtype=np.float32)
    hsv[..., 1] = 1

    mag, ang = cv2.cartToPolar(im1, im2)
    hsv[..., 0] = ang * 180 / np.pi
    hsv[..., 2] = cv2.normalize(mag, None, 0, 1, cv2.NORM_MINMAX)

    return cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB) 
開發者ID:DLR-RM,項目名稱:BlenderProc,代碼行數:22,代碼來源:utils.py

示例10: hog

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def hog(img):
    gx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
    gy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
    mag, ang = cv2.cartToPolar(gx, gy)
    bins = np.int32(bin_n*ang/(2*np.pi))    # quantizing binvalues in (0...16)
    bin_cells = bins[:10,:10], bins[10:,:10], bins[:10,10:], bins[10:,10:]
    mag_cells = mag[:10,:10], mag[10:,:10], mag[:10,10:], mag[10:,10:]
    hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
    hist = np.hstack(hists)     # hist is a 64 bit vector
    return hist
## [hog] 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:13,代碼來源:hogsvm.py

示例11: hog

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def hog(img):
    gx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
    gy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
    mag, ang = cv2.cartToPolar(gx, gy)
    bins = np.int32(bin_n * ang / (2 * np.pi))  # quantizing binvalues in (0...16)
    bin_cells = bins[:10, :10], bins[10:, :10], bins[:10, 10:], bins[10:, 10:]
    mag_cells = mag[:10, :10], mag[10:, :10], mag[:10, 10:], mag[10:, 10:]
    hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
    hist = np.hstack(hists)  # hist is a 64 bit vector
    return hist


# 最後 和前 一樣 我們將大圖分割成小圖。使用每個數字的前 250 個作 為訓練數據
#  後 250 個作為測試數據 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:16,代碼來源:47.2-使用SVM進行-手寫數據OCR.py

示例12: flow2rgb

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def flow2rgb(flow):
    hsv = np.zeros(list(flow.shape[:-1]) + [3], dtype=np.uint8)
    hsv[..., 1] = 255
    mag, ang = cv2.cartToPolar(flow[..., 0], flow[..., 1])
    hsv[..., 0] = ang * 180 / np.pi / 2
    hsv[..., 2] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX)
    return cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB) 
開發者ID:orsic,項目名稱:swiftnet,代碼行數:9,代碼來源:flow_utils.py

示例13: show_flow

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def show_flow(flow):
    # Use Hue, Saturation, Value colour model
    hsv = np.zeros((flow.shape[0], flow.shape[1], 3), dtype=np.uint8)
    hsv[..., 1] = 255

    mag, ang = cv2.cartToPolar(flow[..., 0], flow[..., 1])
    hsv[..., 0] = ang * 180 / np.pi / 2
    hsv[..., 2] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX)
    bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
    plt.imshow(bgr)
    plt.show() 
開發者ID:tobiasfshr,項目名稱:MOTSFusion,代碼行數:13,代碼來源:visualization_utils.py

示例14: flow2im

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def flow2im(flow):
    flow_npy = np.array(flow.detach().cpu().numpy().transpose(1, 2, 0), np.float32)
    shape = flow_npy.shape[:-1]
    hsv = np.zeros(shape + (3,), dtype=np.uint8)
    hsv[..., 2] = 255

    mag, ang = cv2.cartToPolar(flow_npy[..., 0], flow_npy[..., 1])
    hsv[..., 0] = ang * 180 / np.pi / 2
    hsv[..., 1] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX)
    bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
    return bgr 
開發者ID:Lotayou,項目名稱:everybody_dance_now_pytorch,代碼行數:13,代碼來源:networks_modified.py

示例15: denseOpticalFlow

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import cartToPolar [as 別名]
def denseOpticalFlow():
    # use 0 for webcam capturing
    # cap = cv2.VideoCapture(0)

    cap = cv2.VideoCapture('test/Pedestrian overpass.mp4')
    ret, frame1 = cap.read()
    prvs = cv2.cvtColor(frame1,cv2.COLOR_BGR2GRAY)
    hsv = np.zeros_like(frame1)
    hsv[...,1] = 255

    while(1):
        ret, frame2 = cap.read()
        next = cv2.cvtColor(frame2,cv2.COLOR_BGR2GRAY)
        flow = cv2.calcOpticalFlowFarneback(prvs,next, None, 0.5, 3, 15, 3, 5, 1.2, 0)
        mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1])

        hsv[...,0] = ang*180/np.pi/2
        hsv[...,2] = cv2.normalize(mag,None,0,255,cv2.NORM_MINMAX)

        # print(np.sum(mag[100:300, 100:300]))
        if (np.sum(mag)> 100000):
            print('motion detected')

        bgr = cv2.cvtColor(hsv,cv2.COLOR_HSV2BGR)
        cv2.imshow('frame2',bgr)

        k = cv2.waitKey(30) & 0xff
        if k == 27:
            break
        elif k == ord('s'):
            cv2.imwrite('opticalfb.png',frame2)
            cv2.imwrite('opticalhsv.png',bgr)
        prvs = next

    cap.release()
    cv2.destroyAllWindows() 
開發者ID:sahibdhanjal,項目名稱:Mask-RCNN-Pedestrian-Detection,代碼行數:38,代碼來源:opticalFlow.py


注:本文中的cv2.cartToPolar方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。