Python Opencv Cuda GPU 图像处理 (计算结果与CPU不一样)

Opencv Cuda GPU 图像处理 (计算结果与CPU不一样)
上代码

import cv2
import numpy as np

gpuImg = cv2.cuda_GpuMat()
def cv_show(name, image):
    cv2.namedWindow(name, cv2.WINDOW_NORMAL)
    cv2.imshow(name, image)

    cv2.waitKey(0)
    cv2.destroyAllWindows()
def getGpuResize(src):
    global gpuImg
    basePixSize = 1280
    height = src.shape[0]
    width = src.shape[1]
    print('height:', height)
    print('width:', width)
    largeSize = max(height, width)
    resizeRate = basePixSize/largeSize
    gpuImg.upload(src)
    gpuDst = cv2.cuda.resize(gpuImg, (int(width*resizeRate),int(height*resizeRate)))
    return gpuDst

def getGpuCircles(gpuSrc,src):
    # gpuSrc = cv2.cuda.cvtColor(gpuSrc, cv2.COLOR_BGR2GRAY)
    ksize = (5,5)
    gpuFilter = cv2.cuda.createGaussianFilter(srcType=cv2.CV_8UC1, dstType=cv2.CV_8UC1, ksize=ksize, sigma1=0, sigma2=0)
    gpuSrc = cv2.cuda_Filter.apply(gpuFilter, gpuSrc)
    help(cv2.cuda.createHoughCirclesDetector)
    # ret, gpuSrc = cv2.cuda.threshold(gpuSrc, 100, 255, cv2.THRESH_BINARY)
    detector = cv2.cuda.createHoughCirclesDetector(dp=1, minDist=1000, cannyThreshold=110, votesThreshold=90,
                                                   minRadius=400,
                                                   maxRadius=510)  # 100/110/50/445/510 or 150/110/50/430/510/MINRADIUS260
    cuCircles = detector.detect(gpuSrc)
    circles = cuCircles.download()
    print("circles0:", circles)
    print(circles.shape)
    if circles is not None:  # detect circles
        circles = np.uint0(np.around(circles))
        print("circles1:", circles)
    for circle in circles[0, :]:
        dst = cv2.circle(src, (circle[0], circle[1]), circle[2], (255, 0, 255), 2)
    return dst



if __name__ == '__main__':
    img = cv2.imread('./01.jpeg', cv2.IMREAD_GRAYSCALE)
    cuImg = getGpuResize(img)
    img = cuImg.download()
    # print(img.shape)
    # cv_show('img', img)
    dst = getGpuCircles(cuImg, img)
    cv_show('res', dst)

GPU 有没有加速不知道,但是检测的圆还是错的,设置的参数根本没有对结果产生约束。
老铁,怎么办?
还是用CPU吧

你可能感兴趣的:(Basler,Camera,opencv)