Ov7670 and raspberry pi pico

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Saj555
 
Posts: 2
Joined: Mon Jan 23, 2023 3:47 am

Ov7670 and raspberry pi pico

Post by Saj555 »

I try to capture and save a small photo with ov7670 camera module and save it to raspberry pi PICO internal memory as a BMP file format using circuitpython liberaries. any solution or sample code?

first, i tried to view color bars test pattern in this way:
captured image with ov7670 into raspberry pi pico internal memory
Asked today
Modified today
Viewed 5 times

0


I try to capture and save a small photo with ov7670 camera module and save it to raspberry pi PICO internal memory as a BMP file format using circuitpython liberaries. any solution or sample code?

first, i tried to view color bars test pattern in this way:

Code: Select all

import time
import board
import busio
import digitalio
import storage
from adafruit_bitmapsaver import save_pixels
from ulab import numpy as np

from displayio import (
    Bitmap,
    Group,
    TileGrid,
    Palette,
    ColorConverter,
    Colorspace,
)

from adafruit_ov7670 import (
    OV7670,
    OV7670_SIZE_DIV8,
    OV7670_SIZE_DIV16,
    OV7670_COLOR_RGB,
    OV7670_COLOR_YUV,
    OV7670_TEST_PATTERN_COLOR_BAR
)
with digitalio.DigitalInOut(board.GP10) as reset:
    reset.switch_to_output(False)
    time.sleep(0.001)
    bus = busio.I2C(board.GP1, board.GP0)
cam = OV7670(
    bus,
    data_pins=[
        board.GP12,
        board.GP13,
        board.GP14,
        board.GP15,
        board.GP16,
        board.GP17,
        board.GP18,
        board.GP19,
    ],  
    clock=board.GP11,  
    vsync=board.GP7,  
    href=board.GP21,  
    mclk=board.GP20,  
    shutdown=None,
    reset=board.GP10,
)
cam.size = OV7670_SIZE_DIV8
cam.colorspace = OV7670_COLOR_RGB
cam.test_pattern = OV7670_TEST_PATTERN_COLOR_BAR
bitmap = Bitmap(cam.width,cam.height, 65535)   
arr = np.zeros((2*cam.width, 2*cam.height), dtype=np.uint16)
cam.capture(arr)
palette=Palette(cam.width*cam.height)
for y in range(cam.height):
    for x in range(cam.width):
        palette[y*cam.width+x]=arr[x,y]     
x=0
y=0
for y in range(cam.height):
    for x in range(cam.width):
         bitmap[x,y]=y*cam.width+x
save_pixels('/test.bmp', bitmap, palette)
print("done")
But the result is the attached file

what s the problem? how can i get a clear image?
Attachments
Code result
Code result
qEJeU.png (317 Bytes) Viewed 66 times
Last edited by adafruit_support_carter on Mon Jan 30, 2023 3:27 pm, edited 1 time in total.

User avatar
bidrohini
 
Posts: 202
Joined: Thu Oct 20, 2022 10:03 am

Re: Ov7670 and raspberry pi pico

Post by bidrohini »

You can cross-check your wiring and settings with this one: https://ashishware.com/2022/09/03/pipic ... ification/

User avatar
Saj555
 
Posts: 2
Joined: Mon Jan 23, 2023 3:47 am

Re: Ov7670 and raspberry pi pico

Post by Saj555 »

thanks for your reply
as the output format of ov7670 is in RGB565 and windows bitmap format is in RGB888, i used this approach for conversion:

Code: Select all

def RGB(pixel):
    R5=pixel >> 11
    G6=(pixel & 0b11111100000) >> 5
    B5= pixel & 0b11111
    
    R8 = round(255/31 * R5)
    G8 = round(255/63 * G6)
    B8 = round(255/31 * B5)

    return (R8,G8,B8)
palette=Palette(cam.width*cam.height)
for y in range(0,cam.height):
    for x in range(0,cam.width):
        palette[y*cam.width+x] =RGB(arr[x,y])
         
x=0
y=0

for y in range(0,cam.height):
    for x in range(0,cam.width):
         bitmap[x,y]=y*cam.width+x
save_pixels('/test3.bmp', bitmap, palette )

so the result was better now i m wondering why the vertical bars appear

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”