国旗识别作业用到python的知识点整理

Datafeame

1.新建

DataFrame(np.random.randn(9))

2.合并

pd.merge(df1,all_color_hist,left_index=True,right_index=True)

3.删除列

merge1.drop(['dss'],axis=1)

4.索引元素

merge1.loc[i][0]

5.从数组获得值

all_color_proportion[0]=color_proportion

6.保存

pd.to_csv('../3_data/all_feature.csv',header=None)

7.读取

pd.read_csv('../3_data/all_feature.csv',header=None)


opencv

1.读取文中名的图片

def cv_imread(file_path):
    cv_img=cv2.imdecode(np.fromfile(file_path,dtype=np.uint8),-1)
    return cv_img

2.matplotlib和opencv的RGB是反的

matplotlib显示顺序是R,G,B;opencv的顺序是B,G,R。

3.获得图片的高和宽

    img_high=image.shape[0]
    img_width=image.shape[1]   

4.读取像素点

先行,后列。和x,y轴不同

image[img_high,img_width]

5.获取一部分区域数据

image=image[a:b,c:d]

6.将RGB转换为HSV

HSV=cv2.cvtColor(image,cv2.COLOR_BGR2HSV)

7.制作掩模

第一个变量中的元素在第二个和第三个元素之间就返回白,不然返回黑

mask=cv2.inRange(HSV,lower,upper)

8.获得直方图

hist_mask = cv2.calcHist([mask],[0],None,[2],[0,256])


保存txt

doc=open('../杜胜盛.txt','w',encoding='utf-8')

print(filename[:-4],',',Ypred,file=doc)

print(filename,merge1.loc[i][0],file=doc)
doc.close()

猜你喜欢

转载自blog.csdn.net/dss875914213/article/details/85115699