很多人说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