我试图用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
我使用的图像如下所示:
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结果:
C++结果:
即使C++运行完整的程序~2X,但霍夫变换速度很慢。为什么会这样?这是非常违反直觉的。我错过了什么?在