当前位置:网站首页>五、图像像素统计
五、图像像素统计
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()
边栏推荐
- 【Clustrmaps】访客统计
- 【Attention】Visual Attention Network
- SQL repair duplicate data
- Spring, summer, autumn and winter with Miss Zhang (2)
- 迁移学习——Transitive Transfer Learning
- 并发编程学习笔记 之 Lock锁及其实现类ReentrantLock、ReentrantReadWriteLock和StampedLock的基本用法
- 【DL】搭建卷积神经网络用于回归预测(数据+代码详细教程)
- [semantic segmentation] full attention network for semantic segmentation
- 【Transformer】ACMix:On the Integration of Self-Attention and Convolution
- Semaphore (semaphore) for learning notes of concurrent programming
猜你喜欢

并发编程学习笔记 之 工具类Semaphore(信号量)

【卷积核设计】Scaling Up Your Kernels to 31x31: Revisiting Large Kernel Design in CNNs

Flink, the mainstream real-time stream processing computing framework, is the first experience.

虚假新闻检测论文阅读(五):A Semi-supervised Learning Method for Fake News Detection in Social Media

【Transformer】SOFT: Softmax-free Transformer with Linear Complexity

【目标检测】KL-Loss:Bounding Box Regression with Uncertainty for Accurate Object Detection

Lock lock of concurrent programming learning notes and its implementation basic usage of reentrantlock, reentrantreadwritelock and stampedlock

Centos7 silently installs Oracle

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

Realize the scheduled backup of MySQL database in Linux environment through simple script (mysqldump command backup)
随机推荐
第2周学习:卷积神经网络基础
Research on the implementation principle of reentrantlock in concurrent programming learning notes
【Transformer】TransMix: Attend to Mix for Vision Transformers
Markdown syntax
【Transformer】AdaViT: Adaptive Tokens for Efficient Vision Transformer
Thinkphp6 pipeline mode pipeline use
isAccessible()方法:使用反射技巧让你的性能提升数倍
Operation commands in anaconda, such as removing old environment, adding new environment, viewing environment, installing library, cleaning cache, etc
[semantic segmentation] Introduction to mapillary dataset
Detailed explanation of atomic operation classes atomicreference and atomicstampedreference in learning notes of concurrent programming
【语义分割】Fully Attentional Network for Semantic Segmentation
微信小程序源码获取(附工具的下载)
SQL repair duplicate data
Flutter正在被悄悄放弃?浅析Flutter的未来
Nailing alarm script
Lock lock of concurrent programming learning notes and its implementation basic usage of reentrantlock, reentrantreadwritelock and stampedlock
[image classification] how to use mmclassification to train your classification model
Show profiles of MySQL is used.
虚假新闻检测论文阅读(一):Fake News Detection using Semi-Supervised Graph Convolutional Network
ANR优化:导致 OOM 崩溃及相对应的解决方案