@@ -355,15 +355,15 @@ class OV5640(DVP_Camera):
355355
356356 _ratio_table = [
357357 # mw, mh, sx, sy, ex, ey, ox, oy, tx, ty
358- [2560 , 1920 , 0 , 0 , 2623 , 1951 , 32 , 16 , 2844 , 1968 ], # 4x3
359- [2560 , 1704 , 0 , 110 , 2623 , 1843 , 32 , 16 , 2844 , 1752 ], # 3x2
360- [2560 , 1600 , 0 , 160 , 2623 , 1791 , 32 , 16 , 2844 , 1648 ], # 16x10
361- [2560 , 1536 , 0 , 192 , 2623 , 1759 , 32 , 16 , 2844 , 1584 ], # 5x3
362- [2560 , 1440 , 0 , 240 , 2623 , 1711 , 32 , 16 , 2844 , 1488 ], # 16x9
363- [2560 , 1080 , 0 , 420 , 2623 , 1531 , 32 , 16 , 2844 , 1128 ], # 21x9
364- [2400 , 1920 , 80 , 0 , 2543 , 1951 , 32 , 16 , 2684 , 1968 ], # 5x4
365- [1920 , 1920 , 320 , 0 , 2543 , 1951 , 32 , 16 , 2684 , 1968 ], # 1x1
366- [1088 , 1920 , 736 , 0 , 1887 , 1951 , 32 , 16 , 1884 , 1968 ], # 9x16
358+ [2560 , 1920 , 0 , 0 , 2623 , 1951 , 32 , 16 , 2844 , 1968 ], # 4x3
359+ [2560 , 1704 , 0 , 110 , 2623 , 1843 , 32 , 16 , 2844 , 1752 ], # 3x2
360+ [2560 , 1600 , 0 , 160 , 2623 , 1791 , 32 , 16 , 2844 , 1648 ], # 16x10
361+ [2560 , 1536 , 0 , 192 , 2623 , 1759 , 32 , 16 , 2844 , 1584 ], # 5x3
362+ [2560 , 1440 , 0 , 240 , 2623 , 1711 , 32 , 16 , 2844 , 1488 ], # 16x9
363+ [2560 , 1080 , 0 , 420 , 2623 , 1531 , 32 , 16 , 2844 , 1128 ], # 21x9
364+ [2400 , 1920 , 80 , 0 , 2543 , 1951 , 32 , 16 , 2684 , 1968 ], # 5x4
365+ [1920 , 1920 , 320 , 0 , 2543 , 1951 , 32 , 16 , 2684 , 1968 ], # 1x1
366+ [1088 , 1920 , 736 , 0 , 1887 , 1951 , 32 , 16 , 1884 , 1968 ], # 9x16
367367 ]
368368
369369 _pll_pre_div2x_factors = [1 , 1 , 2 , 3 , 4 , 1.5 , 6 , 2.5 , 8 ]
@@ -875,13 +875,10 @@ class OV5640(DVP_Camera):
875875 def __init__ (
876876 self ,
877877 i2c ,
878- i2c_address = 0x3C ,
879- num_data_pins = 1
878+ i2c_address = 0x3C
880879 ):
881- super ().__init__ (i2c , i2c_address , ( 240 , 320 , 2 ) )
880+ super ().__init__ (i2c , i2c_address )
882881
883- # self.soft_reset()
884- # sleep_us(1_000_000)
885882 self .write_list (self ._sensor_default_regs )
886883
887884 self ._colorspace = self .OV5640_COLOR_RGB
@@ -950,7 +947,6 @@ def write_list(self, data):
950947 for i in range (len (data ) // 2 ):
951948 reg = data [i * 2 ]
952949 value = data [i * 2 + 1 ]
953- print (i , reg , value )
954950 if reg == self ._REG_DLY :
955951 sleep_us (value )
956952 else :
@@ -999,16 +995,15 @@ def _set_size_and_colorspace(self) -> None:
999995
1000996 self ._set_image_options ()
1001997
1002- # if self._colorspace == self.OV5640_COLOR_JPEG:
1003- # sys_mul = 200
1004- # if size < self.OV5640_SIZE_QVGA:
1005- # sys_mul = 160
1006- # if size < self.OV5640_SIZE_XGA:
1007- # sys_mul = 180
1008- # self._set_pll(False, sys_mul, 4, 2, False, 2, True, 4)
1009- # else:
1010- # self._set_pll(False, 32, 1, 1, False, 1, True, 4)
1011- self ._set_pll (False , 32 , 1 , 1 , False , 1 , True , 4 )
998+ if self ._colorspace == self .OV5640_COLOR_JPEG :
999+ sys_mul = 200
1000+ if size < self .OV5640_SIZE_QVGA :
1001+ sys_mul = 160
1002+ if size < self .OV5640_SIZE_XGA :
1003+ sys_mul = 180
1004+ self ._set_pll (False , sys_mul , 4 , 2 , False , 2 , True , 4 )
1005+ else :
1006+ self ._set_pll (False , 32 , 1 , 1 , False , 1 , True , 4 )
10121007
10131008 self ._set_colorspace ()
10141009
@@ -1121,4 +1116,11 @@ def read(self, image = None):
11211116 Returns:
11221117 tuple: (success, frame)
11231118 """
1124- return (True , cv2 .cvtColor (self .buffer , cv2 .COLOR_BayerRG2BGR , image ))
1119+ if self ._colorspace == self .OV5640_COLOR_RGB :
1120+ return (True , cv2 .cvtColor (self .buffer , cv2 .COLOR_BGR5652BGR , image ))
1121+ elif self ._colorspace == self .OV5640_COLOR_GRAYSCALE :
1122+ return (True , cv2 .cvtColor (self .buffer , cv2 .COLOR_GRAY2BGR , image ))
1123+ else :
1124+ NotImplementedError (
1125+ f"OV5640:Reading images in colorspace { self ._colorspace } is not yet implemented."
1126+ )
0 commit comments