opencv python c++区别_opencvpython比c++快?

这篇博客探讨了使用Python和C++实现OpenCV的HoughCircle函数时的性能差异。作者发现在处理时间上,Python版本竟然比C++版本更快,这与直觉相反。文章展示了测试代码和结果,并询问了可能的原因。
摘要由CSDN通过智能技术生成

我试图用python和c++来计时houghcircle,看看c++是否在处理时间上提供了优势(直觉上应该!)在

版本python:3.6.4

gcc编译器:gcc(Ubuntu 5.4.0-6ubuntu1~16.04.9)5.4.0 20160609

cmake:3.5.1版

开放式CV:3.4.1I actually installed opencv using anaconda. Surprisingly c++ version

also worked

我使用的图像如下所示:

1sKj7.png

Python代码import cv2

import time

import sys

def hough_transform(src,dp,minDist,param1=100,param2=100,minRadius=0,maxRadius=0):

gray = cv2.cvtColor(src,cv2.COLOR_RGB2GRAY)

start_time = time.time()

circles=cv2.HoughCircles(gray,

cv2.HOUGH_GRADIENT,

dp = dp,

minDist = minDist,

param1=param1,

param2=param2,

minRadius=minRadius,

maxRadius=maxRadius)

end_time = time.time()

print("Time taken for hough circle transform is : {}".format(end_time-start_time))

# if circles is not None:

# circles = circles.reshape(circles.shape[1],circles.shape[2])

# else:

# raise ValueError("ERROR!!!!!! circle not detected try tweaking the parameters or the min and max radius")

#

# a = input("enter 1 to visualize")

# if int(a) == 1 :

# for circle in circles:

# center = (circle[0],circle[1])

# radius = circle[2]

# cv2.circle(src, center, radius, (255,0,0), 5)

#

# cv2.namedWindow("Hough circle",cv2.WINDOW_NORMAL)

# cv2.imshow("Hough circle",src)

# cv2.waitKey(0)

# cv2.destroyAllWindows()

#

#

return

if __name__ == "__main__":

if len(sys.argv) != 2:

raise ValueError("usage: python hough_circle.py ")

image = cv2.imread(sys.argv[1])

image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)

hough_transform(image,1.7,100,50,30,690,700)

C++代码< /H1>

^{pr2}$

我希望C++ Hough变换能达到ACE Python,但实际上发生了相反的情况。在

Python结果:

fuA55.png

C++结果:

mO46Y.png

即使C++运行完整的程序~2X,但霍夫变换速度很慢。为什么会这样?这是非常违反直觉的。我错过了什么?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值