欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

opencv预处理图像

程序员文章站 2022-03-06 21:21:40
...

1 改变图像大小
标题看起来了简单,但是改变图像大小却对小目标的检测有利。cv2中CV_INTER_NN、CV_INTER_LINEAR 、CV_INTER_AREA、CV_INTER_CUBIC到底什么条件用什么呢?查看opencv文档
INTER_AREA - resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire’-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method.
为什么这里的缩放大小采取32的倍数呢,是因为自然场景OCR检测(YOLOv3+CRNN),CRNN论文中采用的就是高度为32的

def resize_image2(w, h):
    resize_w = w
    resize_h = h

    # limit the max side
    if max(resize_h, resize_w) > MAX_LEN:
        ratio = float(MAX_LEN) / resize_h if resize_h > resize_w else float(MAX_LEN) / resize_w
    else:
        ratio = 1.
    resize_h = int(resize_h * ratio)
    resize_w = int(resize_w * ratio)
    resize_h = resize_h if resize_h % 32 == 0 else (resize_h // 32 + 1) * 32
    resize_w = resize_w if resize_w % 32 == 0 else (resize_w // 32 + 1) * 32
    return resize_w, resize_h