python类INTER_CUBIC的实例源码

logoPredictor.py 文件源码 项目:vehicle_brand_classification_CNN 作者: nanoc812 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def loadImgs(imgsfolder, rows, cols):
    myfiles = glob.glob(imgsfolder+'*.jpg', 0)
    nPics = len(myfiles)
    X = np.zeros((nPics, rows, cols), dtype = 'uint8')
    i = 0; imgNames = []
    for filepath in myfiles:
        sd = filepath.rfind('/'); ed = filepath.find('.'); filename = filepath[int(sd+1):int(ed)]
        imgNames.append(filename)  

        temp = cv2.imread(filepath, 0)
        if temp == None:
            continue
        elif temp.size < 1000:
            continue
        elif temp.shape == [rows, cols, 1]:
            X[i,:,:] = temp
        else:
            X[i,:,:] = cv2.resize(temp,(cols, rows), interpolation = cv2.INTER_CUBIC)
        i += 1
    return X, imgNames
recognize_line.py 文件源码 项目:WeiQiRecognition 作者: JDython 项目源码 文件源码 阅读 53 收藏 0 点赞 0 评论 0
def lineRecognizer(path):
    '''
    :param path ????????
    :returns lines_data ?????????resize_pic ??????
    '''
    img = cv2.imread(path,cv2.IMREAD_GRAYSCALE)
    resize_pic=img
    #resize_pic=cv2.resize(img,(640,480),interpolation=cv2.INTER_CUBIC)
    edges = cv2.Canny(resize_pic,50,150)
    lines_data = cv2.HoughLines(edges,1,np.pi/180,150)
    return lines_data,resize_pic
scan2.py 文件源码 项目:card-scanner 作者: RFVenter 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def filter_image(image, canny1=10, canny2=10, show=False):
    # compute the ratio of the old height to the new height, and resize it
    image = imutils.resize(image, height=scale_factor, interpolation=cv2.INTER_CUBIC)

    # convert the image to grayscale, blur it, and find edges in the image
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, (5, 5), 0)
    edged = cv2.Canny(gray, canny1, canny2)

    # show the image(s)
    if show:
        cv2.imshow("Edged", edged)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

    return edged
scan.py 文件源码 项目:card-scanner 作者: RFVenter 项目源码 文件源码 阅读 60 收藏 0 点赞 0 评论 0
def filter_image(image, canny1=10, canny2=10, show=False):
    # compute the ratio of the old height to the new height, and resize it
    image = imutils.resize(image, height=scale_factor, interpolation=cv2.INTER_CUBIC)

    # convert the image to grayscale, blur it, and find edges in the image
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, (5, 5), 0)
    edged = cv2.Canny(gray, canny1, canny2)

    # show the image(s)
    if show:
        cv2.imshow("Edged", edged)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

    return edged
logoSet.py 文件源码 项目:vehicle_brand_classification_CNN 作者: nanoc812 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def loadLogoSet(path, rows,cols,test_data_rate=0.15):
    random.seed(612)
    _, imgID = readItems('data.txt')
    y, _ = modelDict(path)
    nPics =  len(y)
    faceassset = np.zeros((nPics,rows,cols), dtype = np.uint8) ### gray images
    noImg = []
    for i in range(nPics):
        temp = cv2.imread(path +'logo/'+imgID[i]+'.jpg', 0)
        if temp == None:
            noImg.append(i)
        elif temp.size < 1000:
            noImg.append(i)
        else:
            temp = cv2.resize(temp,(cols, rows), interpolation = cv2.INTER_CUBIC)
            faceassset[i,:,:] = temp
    y = np.delete(y, noImg,0); faceassset = np.delete(faceassset, noImg, 0)
    nPics = len(y)
    index = random.sample(np.arange(nPics), int(nPics*test_data_rate))
    x_test = faceassset[index,:,:]; x_train = np.delete(faceassset, index, 0)
    y_test = y[index]; y_train = np.delete(y, index, 0)
    return (x_train, y_train), (x_test, y_test)
list_image_data_provider.py 文件源码 项目:tfplus 作者: renmengye 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_batch_idx(self, idx):
        hh = self.inp_height
        ww = self.inp_width
        x = np.zeros([len(idx), hh, ww, 3], dtype='float32')
        orig_height = []
        orig_width = []
        ids = []
        for kk, ii in enumerate(idx):
            fname = self.ids[ii]
            ids.append('{:06}'.format(ii))
            x_ = cv2.imread(fname).astype('float32') / 255
            x[kk] = cv2.resize(
                x_, (self.inp_width, self.inp_height),
                interpolation=cv2.INTER_CUBIC)
            orig_height.append(x_.shape[0])
            orig_width.append(x_.shape[1])
            pass
        return {
            'x': x,
            'orig_height': np.array(orig_height),
            'orig_width': np.array(orig_width),
            'id': ids
        }
measure_map.py 文件源码 项目:AerialCrackDetection_Keras 作者: TTMRonald 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def format_img(img, C):
    img_min_side = float(C.im_size)
    (height,width,_) = img.shape

    if width <= height:
        f = img_min_side/width
        new_height = int(f * height)
        new_width = int(img_min_side)
    else:
        f = img_min_side/height
        new_width = int(f * width)
        new_height = int(img_min_side)
    fx = width/float(new_width)
    fy = height/float(new_height)
    img = cv2.resize(img, (new_width, new_height), interpolation=cv2.INTER_CUBIC)
    img = img[:, :, (2, 1, 0)]
    img = img.astype(np.float32)
    img[:, :, 0] -= C.img_channel_mean[0]
    img[:, :, 1] -= C.img_channel_mean[1]
    img[:, :, 2] -= C.img_channel_mean[2]
    img /= C.img_scaling_factor
    img = np.transpose(img, (2, 0, 1))
    img = np.expand_dims(img, axis=0)
    return img, fx, fy
measure_map.py 文件源码 项目:keras-frcnn 作者: yhenon 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def format_img(img, C):
    img_min_side = float(C.im_size)
    (height,width,_) = img.shape

    if width <= height:
        f = img_min_side/width
        new_height = int(f * height)
        new_width = int(img_min_side)
    else:
        f = img_min_side/height
        new_width = int(f * width)
        new_height = int(img_min_side)
    fx = width/float(new_width)
    fy = height/float(new_height)
    img = cv2.resize(img, (new_width, new_height), interpolation=cv2.INTER_CUBIC)
    img = img[:, :, (2, 1, 0)]
    img = img.astype(np.float32)
    img[:, :, 0] -= C.img_channel_mean[0]
    img[:, :, 1] -= C.img_channel_mean[1]
    img[:, :, 2] -= C.img_channel_mean[2]
    img /= C.img_scaling_factor
    img = np.transpose(img, (2, 0, 1))
    img = np.expand_dims(img, axis=0)
    return img, fx, fy
dataloader.py 文件源码 项目:MIL.pytorch 作者: gujiuxiang 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def preprocess_vgg19_mil(Image):
    if len(Image.shape) == 2:
        Image = Image[:, :, np.newaxis]
        Image = np.concatenate((Image, Image, Image), axis=2)

    mean = np.array([[[103.939, 116.779, 123.68]]]);
    base_image_size = 565;
    Image = cv2.resize(np.transpose(Image, axes=(1, 2, 0)), (base_image_size, base_image_size), interpolation=cv2.INTER_CUBIC)
    Image_orig = Image.astype(np.float32, copy=True)
    Image_orig -= mean
    im = Image_orig
    #im, gr, grr = upsample_image(Image_orig, base_image_size)
    # im = cv2.resize(Image_orig, (base_image_size, base_image_size), interpolation=cv2.INTER_CUBIC)
    im = np.transpose(im, axes=(2, 0, 1))
    im = im[np.newaxis, :, :, :]
    return im
gui_vis.py 文件源码 项目:iGAN 作者: junyanz 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def update_vis(self):
        ims = self.opt_engine.get_images(self.frame_id)

        if ims is not None:
            self.ims = ims

        if self.ims is None:
            return

        ims_show = []
        n_imgs = self.ims.shape[0]
        for n in range(n_imgs):
            # im = ims[n]
            im_s = cv2.resize(self.ims[n], (self.width, self.width), interpolation=cv2.INTER_CUBIC)
            if n == self.select_id and self.topK > 1:
                t = 3  # thickness
                cv2.rectangle(im_s, (t, t), (self.width - t, self.width - t), (0, 255, 0), t)
            im_s = im_s[np.newaxis, ...]
            ims_show.append(im_s)
        if ims_show:
            ims_show = np.concatenate(ims_show, axis=0)
            g_tmp = utils.grid_vis(ims_show, self.grid_size[1], self.grid_size[0]) # (nh, nw)
            self.vis_results = g_tmp.copy()
            self.update()
forest.py 文件源码 项目:checkmymeat 作者: kendricktan 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def predict(url):
    global model      
    # Read image
    image = io.imread(url)
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
    image = cv2.resize(image, (500, 500), interpolation=cv2.INTER_CUBIC)    

    # Use otsu to mask
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    ret, mask = cv2.threshold(gray,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
    mask = cv2.medianBlur(mask, 5)

    features = describe(image, mask)

    state = le.inverse_transform(model.predict([features]))[0]
    return {'type': state}
crop_webface_clean.py 文件源码 项目:tensorflow_face 作者: ZhihengCV 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def preprocess(img):
    results_0 = detector.detect_face(img)
    if len(results_0) != 0:
        result_0 = max(results_0, key=lambda r: r['area'])
    else:
        result_0 = None
    result_1 = detector_dlib.getLargestFaceBoundingBox(img)

    if result_0 is not None and result_1 is not None:
        if result_1.area() * 0.6 > result_0['area']:
            crop_img = detector_dlib.prepocessImg(img, result_1)
        else:
            crop_img = crop_rotate(img, result_0['left_eye'], result_0['right_eye'], result_0['width'])
    elif result_0 is not None and result_1 is None:
        crop_img = crop_rotate(img, result_0['left_eye'], result_0['right_eye'], result_0['width'])
    elif result_0 is None and result_1 is not None:
        crop_img = detector_dlib.prepocessImg(img, result_1)
    else:
        crop_img = img[70:210, 65:185, :]
        crop_img = cv2.resize(crop_img, (96, 112), interpolation=cv2.INTER_CUBIC)
    return crop_img
opencv_functions.py 文件源码 项目:RealtimeFacialEmotionRecognition 作者: sushant3095 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def addEmoji(img,faces,emoji):
  for x,y,w,h in faces:
    # Resize emoji to desired width and height
    dim = max(w,h)
    em = cv.resize(emoji, (dim,dim), interpolation = cv.INTER_CUBIC)

    # Get boolean for transparency
    trans = em.copy()
    trans[em == 0] = 1
    trans[em != 0] = 0

    # Delete all pixels in image where emoji is nonzero
    img[y:y+h,x:x+w,:] *= trans

    # Add emoji on those pixels
    img[y:y+h,x:x+w,:] += em

  return img

# Add emojis to image at specified points and sizes
# Inputs: img is ndarrays of WxHx3
#         emojis is a list of WxHx3 emoji arrays
#         faces is a list of (x,y,w,h) tuples for each face to be replaced
#         Labels is a list of integer labels for each emotion
prepare_data.py 文件源码 项目:cervix-roi-segmentation-by-unet 作者: scottykwok 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def resize_addset(source_folder, target_folder, dsize, pattern=FILE_PATTERN):
    print('Resizing additional set...')
    if not os.path.exists(target_folder): os.makedirs(target_folder)
    for clazz in ClassNames:
        if clazz not in os.listdir(target_folder):
            os.makedirs(os.path.join(target_folder, clazz))

        total_images = glob.glob(os.path.join(source_folder, clazz, pattern))
        total = len(total_images)
        for i, source in enumerate(total_images):
            filename = ntpath.basename(source)
            target = os.path.join(target_folder, clazz, filename.replace('.jpg', '.png'))

            try:
                img = cv2.imread(source)
                img_resized = cv2.resize(img, dsize, interpolation=cv2.INTER_CUBIC)
                cv2.imwrite(target, img_resized)
            except:
                print('-------------------> error in: {}'.format(source))

            if i % 20 == 0:
                print("Resized {}/{} images".format(i, total))
crop.py 文件源码 项目:cervix-roi-segmentation-by-unet 作者: scottykwok 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def cropCircle(img, resize=None):
    if resize:
        if (img.shape[0] > img.shape[1]):
            tile_size = (int(img.shape[1] * resize / img.shape[0]), resize)
        else:
            tile_size = (resize, int(img.shape[0] * resize / img.shape[1]))
        img = cv2.resize(img, dsize=tile_size, interpolation=cv2.INTER_CUBIC)
    else:
        tile_size = img.shape

    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY);
    _, thresh = cv2.threshold(gray, 10, 255, cv2.THRESH_BINARY)

    _, contours, _ = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

    main_contour = sorted(contours, key=cv2.contourArea, reverse=True)[0]

    ff = np.zeros((gray.shape[0], gray.shape[1]), 'uint8')
    cv2.drawContours(ff, main_contour, -1, 1, 15)
    ff_mask = np.zeros((gray.shape[0] + 2, gray.shape[1] + 2), 'uint8')
    cv2.floodFill(ff, ff_mask, (int(gray.shape[1] / 2), int(gray.shape[0] / 2)), 1)

    rect = maxRect(ff)
    rectangle = [min(rect[0], rect[2]), max(rect[0], rect[2]), min(rect[1], rect[3]), max(rect[1], rect[3])]
    img_crop = img[rectangle[0]:rectangle[1], rectangle[2]:rectangle[3]]
    cv2.rectangle(ff, (min(rect[1], rect[3]), min(rect[0], rect[2])), (max(rect[1], rect[3]), max(rect[0], rect[2])), 3,
                  2)

    return [img_crop, rectangle, tile_size]
nutszebra_chainer.py 文件源码 项目:trainer 作者: nutszebra 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _heatmap(x, y, confidences, activations, threshold=0.2):
    channel, height, width = x.shape
    heatmaps = []
    max_activation = 0
    for activation, confidence in six.moves.zip(activations, confidences):
        heatmap = np.zeros((height, width))
        activation = confidence * cv2.resize(activation, (width, height), interpolation=cv2.INTER_CUBIC)
        heatmap = heatmap + activation
        heatmaps.append(heatmap)
        max_activation = np.max([max_activation, np.max(heatmap)])
    for heatmap in heatmaps:
        heatmap[np.where(heatmap <= max_activation * threshold)] = 0.0
    total_heatmap = np.zeros((height, width))
    for heatmap in heatmaps:
        total_heatmap = total_heatmap + heatmap
    return (x, y, heatmaps, total_heatmap)
drive_by_cnn.py 文件源码 项目:CozmoSelfDriveToyUsingCNN 作者: benjafire 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def drive(self):
        ''' Get the image infront and 
        '''
        latest_image = self.cozmo.world.latest_image
        screen  = np.array(latest_image.raw_image)
        screen  = cv2.resize(screen, (200, 120), interpolation=cv2.INTER_CUBIC)                                                         
        cv2.imshow('window1', screen)
        cv2.imwrite("./a.jpg", screen)

        image =  screen.astype(dtype=np.float32)/255.0

        key_code = self.model.y_out.eval(session=self.sess, feed_dict={self.model.x: [image], 
                                              self.model.keep_prob_fc1:1.0, self.model.keep_prob_fc2:1.0, 
                                              self.model.keep_prob_fc3:1.0, self.model.keep_prob_fc4:1.0})

        print ("after judgeing, key_code is", key_code )

        self.go_driving(key_code)
data_feeder.py 文件源码 项目:tf-lcnn 作者: ildoonet 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def get_mnist_data(is_train, image_size, batchsize):
    ds = MNISTCh('train' if is_train else 'test', shuffle=True)

    if is_train:
        augs = [
            imgaug.RandomApplyAug(imgaug.RandomResize((0.8, 1.2), (0.8, 1.2)), 0.3),
            imgaug.RandomApplyAug(imgaug.RotationAndCropValid(15), 0.5),
            imgaug.RandomApplyAug(imgaug.SaltPepperNoise(white_prob=0.01, black_prob=0.01), 0.25),
            imgaug.Resize((224, 224), cv2.INTER_AREA)
        ]
        ds = AugmentImageComponent(ds, augs)
        ds = PrefetchData(ds, 128*10, multiprocessing.cpu_count())
        ds = BatchData(ds, batchsize)
        ds = PrefetchData(ds, 256, 4)
    else:
        # no augmentation, only resizing
        augs = [
            imgaug.Resize((image_size, image_size), cv2.INTER_CUBIC),
        ]
        ds = AugmentImageComponent(ds, augs)
        ds = BatchData(ds, batchsize)
        ds = PrefetchData(ds, 20, 2)
    return ds
deal_code.py 文件源码 项目:LoginSimulation 作者: Byshx 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _remove_line_(self, img):
        # ??????
        newimg = np.zeros(img.shape, np.uint8)
        newimg = cv2.resize(newimg, (img.shape[1], img.shape[0] - top - bottom), interpolation=cv2.INTER_CUBIC)
        for i in range(7, 20):
            for j in range(img.shape[1]):
                newimg[i - top, j] = img[i, j]
        # ???????
        line = []
        for i in range(newimg.shape[0]):
            hasline = False
            if newimg[i, 0] < 100:
                line.append(i)
                hasline = True
            for j in range(newimg.shape[1]):
                if hasline:
                    newimg[i, j] = 0
                else:
                    if newimg[i, j] < 100:
                        newimg[i, j] = 255
                    else:
                        newimg[i, j] = 0
        # top 7 left 7-10 bottom 10
        return newimg
opencv_functions.py 文件源码 项目:HappyNet 作者: danduncan 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def addEmoji(img,faces,emoji):
  for x,y,w,h in faces:
    # Resize emoji to desired width and height
    dim = max(w,h)
    em = cv.resize(emoji, (dim,dim), interpolation = cv.INTER_CUBIC)

    # Get boolean for transparency
    trans = em.copy()
    trans[em == 0] = 1
    trans[em != 0] = 0

    # Delete all pixels in image where emoji is nonzero
    img[y:y+h,x:x+w,:] *= trans

    # Add emoji on those pixels
    img[y:y+h,x:x+w,:] += em

  return img

# Add emojis to image at specified points and sizes
# Inputs: img is ndarrays of WxHx3
#         emojis is a list of WxHx3 emoji arrays
#         faces is a list of (x,y,w,h) tuples for each face to be replaced
#         Labels is a list of integer labels for each emotion
utils.py 文件源码 项目:faststyle 作者: ghwatson 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def imresize(img, scale):
    """Depending on if we scale the image up or down, we use an interpolation
    technique as per OpenCV recommendation.

    :param img:
        3D numpy array of image.
    :param scale:
        float to scale image by in both axes.
    """
    if scale > 1.0:  # use cubic interpolation for upscale.
        img = cv2.resize(img, None, interpolation=cv2.INTER_CUBIC,
                         fx=scale, fy=scale)
    elif scale < 1.0:  # area relation sampling for downscale.
        img = cv2.resize(img, None, interpolation=cv2.INTER_AREA,
                         fx=scale, fy=scale)
    return img
utils.py 文件源码 项目:kaggle-dstl 作者: lopuhin 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def load_image(im_id: str, rgb_only=False, align=True) -> np.ndarray:
    im_rgb = tiff.imread('./three_band/{}.tif'.format(im_id)).transpose([1, 2, 0])
    if rgb_only:
        return im_rgb
    im_p = np.expand_dims(tiff.imread('sixteen_band/{}_P.tif'.format(im_id)), 2)
    im_m = tiff.imread('sixteen_band/{}_M.tif'.format(im_id)).transpose([1, 2, 0])
    im_a = tiff.imread('sixteen_band/{}_A.tif'.format(im_id)).transpose([1, 2, 0])
    w, h = im_rgb.shape[:2]
    if align:
        key = lambda x: '{}_{}'.format(im_id, x)
        im_p, _ = _aligned(im_rgb, im_p, key=key('p'))
        im_m, aligned = _aligned(im_rgb, im_m, im_m[:, :, :3], key=key('m'))
        im_ref = im_m[:, :, -1] if aligned else im_rgb[:, :, 0]
        im_a, _ = _aligned(im_ref, im_a, im_a[:, :, 0], key=key('a'))
    if im_p.shape != im_rgb.shape[:2]:
        im_p = cv2.resize(im_p, (h, w), interpolation=cv2.INTER_CUBIC)
    im_p = np.expand_dims(im_p, 2)
    im_m = cv2.resize(im_m, (h, w), interpolation=cv2.INTER_CUBIC)
    im_a = cv2.resize(im_a, (h, w), interpolation=cv2.INTER_CUBIC)
    return np.concatenate([im_rgb, im_p, im_m, im_a], axis=2)
utils.py 文件源码 项目:kaggle-dstl 作者: lopuhin 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _aligned(im_ref, im, im_to_align=None, key=None):
    w, h = im.shape[:2]
    im_ref = cv2.resize(im_ref, (h, w), interpolation=cv2.INTER_CUBIC)
    im_ref = _preprocess_for_alignment(im_ref)
    if im_to_align is None:
        im_to_align = im
    im_to_align = _preprocess_for_alignment(im_to_align)
    assert im_ref.shape[:2] == im_to_align.shape[:2]
    try:
        cc, warp_matrix = _get_alignment(im_ref, im_to_align, key)
    except cv2.error as e:
        logger.info('Error getting alignment: {}'.format(e))
        return im, False
    else:
        im = cv2.warpAffine(im, warp_matrix, (h, w),
                            flags=cv2.INTER_LINEAR + cv2.WARP_INVERSE_MAP)
        im[im == 0] = np.mean(im)
        return im, True
test_webcam.py 文件源码 项目:tinyYOLOv2 作者: simo23 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def preprocessing(input_image,input_height,input_width):

  resized_image = cv2.resize(input_image,(input_height, input_width), interpolation = cv2.INTER_CUBIC)
  image_data = np.array(resized_image, dtype='f')

  # Normalization [0,255] -> [0,1]
  image_data /= 255.

  # BGR -> RGB? The results do not change much
  # copied_image = image_data
  #image_data[:,:,2] = copied_image[:,:,0]
  #image_data[:,:,0] = copied_image[:,:,2]

  image_array = np.expand_dims(image_data, 0)  # Add batch dimension

  return image_array
test.py 文件源码 项目:tinyYOLOv2 作者: simo23 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def preprocessing(input_img_path,input_height,input_width):

  input_image = cv2.imread(input_img_path)

  # Resize the image and convert to array of float32
  resized_image = cv2.resize(input_image,(input_height, input_width), interpolation = cv2.INTER_CUBIC)
  image_data = np.array(resized_image, dtype='f')

  # Normalization [0,255] -> [0,1]
  image_data /= 255.

  # BGR -> RGB? The results do not change much
  # copied_image = image_data
  #image_data[:,:,2] = copied_image[:,:,0]
  #image_data[:,:,0] = copied_image[:,:,2]

  # Add the dimension relative to the batch size needed for the input placeholder "x"
  image_array = np.expand_dims(image_data, 0)  # Add batch dimension

  return image_array
preprocess.py 文件源码 项目:Fingerprint-Recognition 作者: zhangzimou 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def ridgeComp(img,theta, blockSize,w=3,h=9,alpha=100,beta=1):
    resize=5
    N,M=np.shape(img)
    imgout=np.zeros_like(img)
    imgresizeize=cv2.resizeize(img,None,fx=resize,fy=resize,interpolation = cv2.INTER_CUBIC)
    mask=np.ones((w,h))*beta
    mask[(w-1)/2]=np.ones((1,h))*alpha
    ww=np.arange(-(w-1)/2,(w-1)/2+1)
    hh=np.arange(-(h-1)/2,(h-1)/2+1)
    hh,ww=np.meshgrid(hh,ww)
    for i in xrange((h-1)/2,N-(h-1)/2):
        block_i=i/blockSize
        for j in xrange((h-1)/2,M-(h-1)/2):
            block_j=j/blockSize
            thetaHere=theta[block_i,block_j]
            ii=np.round((i+ww*np.cos(thetaHere)-hh*np.sin(thetaHere))*resize).astype(np.int32)
            jj=np.round((j+ww*np.sin(thetaHere)+hh*np.cos(thetaHere))*resize).astype(np.int32)
            imgout[i,j]=np.sum(imgresizeize[ii,jj]*mask)/(((w-1)*beta+alpha)*h)
preprocessing.py 文件源码 项目:Fingerprint-Recognition 作者: zhangzimou 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def ridgeComp(img,theta, blockSize,w=3,h=9,alpha=100,beta=1):
    resize=5
    N,M=np.shape(img)
    imgout=np.zeros_like(img)
    imgresizeize=cv2.resizeize(img,None,fx=resize,fy=resize,interpolation = cv2.INTER_CUBIC)
    mask=np.ones((w,h))*beta
    mask[(w-1)/2]=np.ones((1,h))*alpha
    ww=np.arange(-(w-1)/2,(w-1)/2+1)
    hh=np.arange(-(h-1)/2,(h-1)/2+1)
    hh,ww=np.meshgrid(hh,ww)
    for i in xrange((h-1)/2,N-(h-1)/2):
        block_i=i/blockSize
        for j in xrange((h-1)/2,M-(h-1)/2):
            block_j=j/blockSize
            thetaHere=theta[block_i,block_j]
            ii=np.round((i+ww*np.cos(thetaHere)-hh*np.sin(thetaHere))*resize).astype(np.int32)
            jj=np.round((j+ww*np.sin(thetaHere)+hh*np.cos(thetaHere))*resize).astype(np.int32)
            imgout[i,j]=np.sum(imgresizeize[ii,jj]*mask)/(((w-1)*beta+alpha)*h)
basic.py 文件源码 项目:Fingerprint-Recognition 作者: zhangzimou 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def binarize2(img,theta,blockSize,h=9):
    resize=5
    N,M=np.shape(img)
    imgout=np.zeros_like(img)
    imgresizeize=cv2.resizeize(img,None,fx=resize,fy=resize,interpolation = cv2.INTER_CUBIC)
    blockMean=blockproc(img,np.mean,(blockSize,blockSize),True)
    hh=np.arange(-(h-1)/2,(h-1)/2+1)
    for i in xrange((h-1)/2,N-(h-1)/2):
        block_i=i/blockSize
        for j in xrange((h-1)/2,M-(h-1)/2):
            block_j=j/blockSize
            thetaHere=theta[block_i,block_j]
            ii=np.round((i-hh*np.sin(thetaHere))*resize).astype(np.int32)
            jj=np.round((j+hh*np.cos(thetaHere))*resize).astype(np.int32)
            imgout[i,j]=255 if (np.mean(imgresizeize[ii,jj])>blockMean[block_i,block_j]) else 0
    return imgout
preprocess.py 文件源码 项目:Fingerprint-Recognition 作者: zhangzimou 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def ridgeComp(img,theta,blockSize,boxSize,h=11):
    resize=8
    N,M=np.shape(img)
    imgout=img.copy()
    imgResize=cv2.resize(img,None,fx=resize,fy=resize,interpolation = cv2.INTER_CUBIC)
    hh=np.arange(-(h-1)/2,(h-1)/2+1)
    for i in xrange(10,N-10):
        block_i = (i-blockSize/2)/boxSize
        if block_i>=theta.shape[0]:
            break
        for j in xrange(10,M-10):
            block_j = (j-blockSize/2)/boxSize
            if block_j>=theta.shape[1]:
                break
            theta0=theta[block_i,block_j]
            ii=np.round((i-hh*np.sin(theta0))*resize).astype(np.int32)
            jj=np.round((j+hh*np.cos(theta0))*resize).astype(np.int32)
            imgout[i,j]=np.mean(imgResize[ii,jj])
    return imgout
basic.py 文件源码 项目:Fingerprint-Recognition 作者: zhangzimou 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def binarize2(img,theta,blockSize,h=9):
    resize=5
    N,M=np.shape(img)
    imgout=np.zeros_like(img)
    imgresizeize=cv2.resizeize(img,None,fx=resize,fy=resize,interpolation = cv2.INTER_CUBIC)
    blockMean=blockproc(img,np.mean,(blockSize,blockSize),True)
    hh=np.arange(-(h-1)/2,(h-1)/2+1)
    for i in xrange((h-1)/2,N-(h-1)/2):
        block_i=i/blockSize
        for j in xrange((h-1)/2,M-(h-1)/2):
            block_j=j/blockSize
            thetaHere=theta[block_i,block_j]
            ii=np.round((i-hh*np.sin(thetaHere))*resize).astype(np.int32)
            jj=np.round((j+hh*np.cos(thetaHere))*resize).astype(np.int32)
            imgout[i,j]=255 if (np.mean(imgresizeize[ii,jj])>blockMean[block_i,block_j]) else 0
    return imgout


问题


面经


文章

微信
公众号

扫码关注公众号