当前位置:网站首页>五、图像像素统计
五、图像像素统计
2022-07-29 05:22:00 【MY头发乱了】
图像区域像素统计
适用于统计图像像素差距较明显,当像素值计算出来后可进行比较。
下面展示一些 内联代码片。
// A code block
var foo = 'bar';
import cv2 as cv,cv2
import matplotlib.pyplot as plt
import numpy as np,time,os
# #不同算子的差异
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()
边栏推荐
- Tear the ORM framework by hand (generic + annotation + reflection)
- SSM integration
- 关于Flow的原理解析
- 第三周周报 ResNet+ResNext
- Activity交互问题,你确定都知道?
- 【Transformer】ATS: Adaptive Token Sampling For Efficient Vision Transformers
- 迁移学习—— Transfer Feature Learning with Joint Distribution Adaptation
- Operation commands in anaconda, such as removing old environment, adding new environment, viewing environment, installing library, cleaning cache, etc
- ASM piling: after learning ASM tree API, you don't have to be afraid of hook anymore
- Thinkphp6 output QR code image format to solve the conflict with debug
猜你喜欢

Spring, summer, autumn and winter with Miss Zhang (2)

Is flutter being quietly abandoned? On the future of flutter
![[network design] convnext:a convnet for the 2020s](/img/c5/fe3771aaa1c4168402bea232190a35.png)
[network design] convnext:a convnet for the 2020s

yum本地源制作

Thinkphp6 output QR code image format to solve the conflict with debug

ASM插桩:学完ASM Tree api,再也不用怕hook了

Reporting Services- Web Service

【Transformer】SegFormer:Simple and Efficient Design for Semantic Segmentation with Transformers

虚假新闻检测论文阅读(二):Semi-Supervised Learning and Graph Neural Networks for Fake News Detection

【Transformer】SOFT: Softmax-free Transformer with Linear Complexity
随机推荐
并发编程学习笔记 之 ReentrantLock实现原理的探究
Detailed explanation of atomic operation classes atomicreference and atomicstampedreference in learning notes of concurrent programming
有价值的博客、面经收集(持续更新)
Technology that deeply understands the principle of MMAP and makes big manufacturers love it
Isaccessible() method: use reflection techniques to improve your performance several times
Detailed explanation of atomic operation class atomicinteger in learning notes of concurrent programming
【语义分割】Mapillary 数据集简介
虚假新闻检测论文阅读(二):Semi-Supervised Learning and Graph Neural Networks for Fake News Detection
迁移学习——Transitive Transfer Learning
[clustmaps] visitor statistics
【语义分割】SETR_Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformer
Most PHP programmers don't understand how to deploy safe code
The third week of postgraduate freshman training: resnet+resnext
Synchronous development with open source projects & codereview & pull request & Fork how to pull the original warehouse
The difference between asyncawait and promise
How to PR an open source composer project
【Transformer】ATS: Adaptive Token Sampling For Efficient Vision Transformers
Detailed explanation of MySQL statistical function count
【Transformer】SOFT: Softmax-free Transformer with Linear Complexity
【Transformer】ACMix:On the Integration of Self-Attention and Convolution