python 手机相机传感器信息计算

传感器信息计算

输入传感器尺寸以上已红米12pro+为例

在这里插入图片描述
输入传感器尺寸 1/1.4英寸 = 0.7142857
输入像素2亿 = 200000000

得到以下结果
和宣传中的传感器信息一致
在这里插入图片描述

附源码
import sympy

class CMosInfo(object):
    """传感器信息计算"""

    def __init__(self):
        self.inch = 1 # 传感器英寸
        self.pixel = 200000000  # 像素点2亿分辨率
        self.heightProportion = 3  # 手机传感器尺寸默认高度比例 默认3
        self.widthPortion = 4  # 宽度比例 默认 4

    def main(self):
        while True:
            self.inch = 0
            equipment_type=input("请输入1或者2(1手机,2相机)")
            if equipment_type == '1':
                self.heightProportion = 3  # 手机传感器尺寸默认高度比例 默认3
                self.widthPortion = 4  # 宽度比例 默认 4
                self.get_coms_info()
            elif equipment_type == '2':
                while True:
                    hf=input("请输入相机类型:(1.全画幅,2.半画幅,3.中画幅,4.M43)")
                    if hf == '1':
                        self.heightProportion = 3  # 手机传感器尺寸默认高度比例 默认3
                        self.widthPortion = 4  # 宽度比例 默认 4
                        self.inch = 2.67
                        break
                    elif hf == '2':
                        self.heightProportion = 2  # 手机传感器尺寸默认高度比例 默认3
                        self.widthPortion = 3  # 宽度比例 默认 4
                        self.inch = 1.7
                        break
                    elif hf == '3':
                        print("仔仔大哥哥没写")
                    elif hf == '4':
                        self.heightProportion = 3  # 手机传感器尺寸默认高度比例 默认3
                        self.widthPortion = 4  # 宽度比例 默认 4
                        self.inch = 1.33
                        break
                    else:
                        print('请重新输入相机类型')
                self.get_coms_info()
            else:
                print("未输入正确类型")

    def get_coms_info(self):
        """手机默认传感器尺寸3:4"""
        if self.inch == 0:
            self.inch=float(input("请输入传感器尺寸(英寸)"))
        self.pixel=input("请输入像素")
        self.count()

    def hypotenuseCm(self):
        cmos = sympy.Symbol('cmos')  # cmos 英寸
        f_cm = (cmos * 2.54).evalf(subs={cmos: self.inch})  # 斜边长度英寸转换厘米
        return f_cm

    def compute_height_and_width(self,f_cm):
        """
            # 计算传感器的长度和宽度
            # 返回元组 宽度和高度 w h
            """
        x = sympy.Symbol('x', positive=True)  # 宽度 正数
        y = sympy.Symbol('y', positive=True)  # 高度 正数
        f1 = x * x + y * y - f_cm * f_cm
        f2 = x * self.heightProportion - y * self.widthPortion
        v = sympy.solve([f1, f2], [x, y])
        return (v[0])

    def photosensitive(self, pixel, width, height):
        """
        传入像素,宽度和高度
        返回单像素尺寸 平方微米um
        """
        # 厘米转换为微米*10000
        width = width * 10000
        height = height * 10000
        f1 = (width * height)/int(pixel)/1.4142 # 除于根号2得到正方形斜边长度

        return f1

    def pixel_height_and_width(self,pixel, heightProportion, widthPortion):
        """
        # 计算图片分辨率
        """
        pixel_x = sympy.Symbol('pixel_x', positive=True)  # 像素点x
        pixel_y = sympy.Symbol('pixel_y', positive=True)  # 像素点y
        f1 = (pixel_x * pixel_y) - int(pixel)
        f2 = (pixel_x * heightProportion) - (pixel_y * widthPortion)
        v = sympy.solve([f1, f2], [pixel_x, pixel_y])
        return (int((v[0])[0]), int((v[0])[1]))

    def count(self):
        """计算"""
        f_cm=self.hypotenuseCm()
        width_and_height = self.compute_height_and_width(f_cm)
        print(f'传感器宽度cm:{width_and_height[0]}cm')
        print(f'传感器高度cm:{width_and_height[1]}cm')
        Single_pixel_area = self.photosensitive(self.pixel, width=width_and_height[0], height=width_and_height[1])
        print(f'单像素感光面积:{Single_pixel_area}um')
        pixel_x_y = self.pixel_height_and_width(self.pixel, self.heightProportion, self.widthPortion)
        print(f'最大分辨率:{pixel_x_y[0]}*{pixel_x_y[1]}')

CMI=CMosInfo()
CMI.main()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值