python运行速度和c_Python与C++之间运行速度对比

很多人说python语言运行速度慢,那么我用一个遍历图片像素的例子做对比。

准备工作

一张2048x1024大小的图片

image.png

opecv 2.0

xcode 8.3

python 2.7 PyCharm

C++代码

//处理边缘

Mat detectEdge(Mat &image)

{

Mat resultImage = image.clone();

int rows = resultImage.rows;

int cols = resultImage.cols;

for(int i = 0;i < rows;i++)

{

for(int j = 0;j < cols;j++)

{

//判断下边

if(i!=rows-1&&resultImage.at(i,j)!=resultImage.at(i+1,j))

{

// road + sidewalk

if (judgeHorizonPixels(resultImage, i, j, road, sidewalk)) {

resultImage.at(i,j)=my_road_sidewalk;

}

// road + car

else if (judgeHorizonPixels(resultImage, i, j, road, car)) {

resultImage.at(i,j)=my_road_car;

}

// road + pole

else if (judgeHorizonPixels(resultImage, i, j, road, pole)) {

resultImage.at(i,j)=my_road_pole;

}

// road

else if(image.at(i,j)==road||image.at(i+1,j)==road){

resultImage.at(i,j)=my_road;

}

// building + pole

else if (judgeHorizonPixels(resultImage, i, j, building, pole)) {

resultImage.at(i,j)=my_building_pole;

}

// building + sidewalk

else if (judgeHorizonPixels(resultImage, i, j, building, sidewalk)) {

resultImage.at(i,j)=my_building_sidewalk;

}

// building + traffic sign

else if (judgeHorizonPixels(resultImage, i, j, building, traffic_sign)) {

resultImage.at(i,j)=my_building_traffic_sign;

}

// building + car

else if (judgeHorizonPixels(resultImage, i, j, building, car)) {

resultImage.at(i,j)=my_building_car;

}

// building + vegetation

else if (judgeHorizonPixels(resultImage, i, j, building, vegetation)) {

resultImage.at(i,j)=my_building_vegetation;

}

// building + sky

else if (judgeHorizonPixels(resultImage, i, j, building, sky)) {

resultImage.at(i,j)=my_bui

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值