当前位置:网站首页>5、 Image pixel statistics
5、 Image pixel statistics
2022-07-29 06:08:00 【My hair is messy】
Image area pixel statistics
It is suitable for statistical image with obvious pixel gap , When the pixel value is calculated, it can be compared .
Here are some Inline code slice .
// A code block
var foo = 'bar';
import cv2 as cv,cv2
import matplotlib.pyplot as plt
import numpy as np,time,os
# # The difference between different operators
def cv_show(img,name):
cv2.imshow(name,img)
cv2.waitKey()
cv2.destroyAllWindows()
def sobel(img):
sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=3)
sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=3)
sobelx = cv2.convertScaleAbs(sobelx)
sobely = cv2.convertScaleAbs(sobely)
sobelxy = cv2.addWeighted(sobelx,0.5,sobely,0.5,0)
return sobelxy
def scharr(img):
scharrx = cv2.Scharr(img,cv2.CV_64F,1,0)
scharry = cv2.Scharr(img,cv2.CV_64F,0,1)
scharrx = cv2.convertScaleAbs(scharrx)
scharry = cv2.convertScaleAbs(scharry)
scharrxy = cv2.addWeighted(scharrx,0.5,scharry,0.5,0)
return scharrxy
def laplacian(img):
laplacian = cv2.Laplacian(img,cv2.CV_64F)
laplacian = cv2.convertScaleAbs(laplacian)
return laplacian
def statistics():
f= open(r'./id_pv.txt', "w")
img_path=r'/data2/enducation/answer_card/answer-card-recognition/id_img'
len_=len(os.listdir(img_path))
for j in range(len_):
img_path_=os.path.join(img_path,f"{j}.jpg")
# img_path_=r"/data2/enducation/answer_card/answer-card-recognition/id_img/21.jpg"
print(img_path_)
src = cv.imread(img_path_)
# cv.imshow("q",src)
h,w,ch = np.shape(src)
scharrx = cv.Scharr(src,cv.CV_64F,1,0)
scharry = cv.Scharr(src,cv.CV_64F,0,1)
scharrx = cv.convertScaleAbs(scharrx)
scharry = cv.convertScaleAbs(scharry)
scharrxy = cv.addWeighted(scharrx,0.5,scharry,0.5,0)
pw=int(w/9)
one_id_pv=[]
for i in range(9):
x1 = i * pw
y1 = 66
x2 = (i + 1) * pw
y2 = h
image = scharrxy[y1:y2, x1:x2,:]
h1,w1,c=image.shape
cv.rectangle(src, (x1, y1), (x2, y2), (100, 108, 255), 1)
#??????
gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
print(gray.shape)
# exit()
#??????????
# cv.imshow("gray",gray)
hest = np.zeros([256],dtype = np.int32)
#??????
pvs = []
for row in range(h1):
for col in range(w1):
pv = gray[row,col]
pvs.append(pv)
hest[pv] +=1
#????????????
x=np.mean(pvs)
one_id_pv.append(int(x))
print(x)
# plt.plot(hest,color = "r")
# plt.xlim([0,256])
# plt.show()
# #?????
# cv.waitKey(0)
# cv.destroyAllWindows()
# card_logger.info(f"{one_id_pv}\n")
f.write(f"{one_id_pv}+{j}\n")
f.write(f"{img_path_}\n\n")
if __name__ == '__main__':
path=r""
img=cv.imread(path)
# sobelxy=sobel(img)
# scharrxy=scharr(img)
# laplacian=laplacian(img)
# res = np.hstack((sobelxy,scharrxy,laplacian))
# cv_show(res, 'res')
statistics()
边栏推荐
- Nifi changed UTC time to CST time
- 性能优化之趣谈线程池:线程开的越多就越好吗?
- 研究生新生培训第二周:卷积神经网络基础
- [clustmaps] visitor statistics
- Jianzhi core taocloud full flash SDS helps build high-performance cloud services
- Ffmpeg creation GIF expression pack tutorial is coming! Say thank you, brother black fly?
- Isaccessible() method: use reflection techniques to improve your performance several times
- 【Transformer】ACMix:On the Integration of Self-Attention and Convolution
- 二、深度学习数据增强方法汇总
- anaconda中移除旧环境、增加新环境、查看环境、安装库、清理缓存等操作命令
猜你喜欢

备份谷歌或其他浏览器插件

【Transformer】AdaViT: Adaptive Tokens for Efficient Vision Transformer

Anr Optimization: cause oom crash and corresponding solutions

预训练语言模型的使用方法

Detailed explanation of MySQL statistical function count

Typical cases of xdfs & China Daily Online Collaborative Editing Platform

ML16 neural network (2)

The third week of postgraduate freshman training: resnet+resnext

Change! Change! Change!

一、常见损失函数的用法
随机推荐
Spring, summer, autumn and winter with Miss Zhang (4)
[image classification] how to use mmclassification to train your classification model
[ml] PMML of machine learning model -- Overview
tensorboard使用
[competition website] collect machine learning / deep learning competition website (continuously updated)
【网络设计】ConvNeXt:A ConvNet for the 2020s
[network design] convnext:a convnet for the 2020s
【Attention】Visual Attention Network
Anr Optimization: cause oom crash and corresponding solutions
Chongqing Avenue cloud bank, as a representative of the software industry, was invited to participate in the signing ceremony of key projects in Yuzhong District
Jianzhi core taocloud full flash SDS helps build high-performance cloud services
3、 How to customize data sets?
研究生新生培训第二周:卷积神经网络基础
Improve quality with intelligence financial imaging platform solution
【bug】XLRDError: Excel xlsx file; not supported
【pycharm】pycharm远程连接服务器
Analysis on the principle of flow
迁移学习——Robust Visual Domain Adaptation with Low-Rank Reconstruction
【语义分割】Mapillary 数据集简介
The third week of postgraduate freshman training: resnet+resnext