espressif / esp32-camera

Apache License 2.0
1.85k stars 631 forks source link

Any support for ov5640 possible? #18

Closed searchingforcode closed 4 years ago

searchingforcode commented 5 years ago

Hi is it possible to integrate ov5640 driver? I found drivers of ov5640 for linux. Can esp32 process ov5640 images? Thanks

msaufyrohmad commented 4 years ago

is there anyone still working on using ov5640 on esp32? i need help to make it happened

sabas1080 commented 4 years ago

I am working in the driver for ov5640, coming soon the pullrequest

You can see my advance in

https://github.com/ElectronicCats/esp32-camera/tree/support-ov5640

your help is welcome ;)

Niek commented 4 years ago

Awesome work @sabas1080 🎉

me-no-dev commented 4 years ago

I also have the driver done. waiting for a board to tune the clocks, because I am not very happy with the frame rates. Other than that, the driver is coming along with other changes. @sabas1080 you might want to throttle down a bit :)

sabas1080 commented 4 years ago

@me-no-dev

that's great, can you share your code? I can help test I have the following hardware

https://www.arducam.com/product/5-mp-ov5640d-cmos-af-camera-module-1-4-inch-module/

kotran88 commented 4 years ago

I am working in the driver for ov5640, coming soon the pullrequest

You can see my advance in

https://github.com/ElectronicCats/esp32-camera/tree/support-ov5640

your help is welcome ;)

I have below error everytime...even though I paste your code on my root directory of my folder funny thing is that even though I deleted 1049 line of camera.c /driver/include/camera.c, it cause same error....

E][camera.c:1049] camera_probe(): Detected camera not supported. [E][camera.c:1249] esp_camera_init(): Camera probe failed with error 0x20004

sabas1080 commented 4 years ago

@me-no-dev something new? can i help trying

@kotran88 my driver my driver is not finished and I have stopped the development waiting for the work of @me-no-dev

misghna commented 4 years ago

@me-no-dev it looks like a lot of people are waiting your driver :) anyluck with the board?

me-no-dev commented 4 years ago

I'm hoping to get the test board in a week or so. The current code IMO is not releasable. I am not happy with the clocks, info is limited and just generally hacks to get it going. Please do understand that I can't just post test code in Espressif repos, but do rest assured that the sensor is working and you will soon have support for it wether I get the results I hope for or not.

pushtoopen commented 4 years ago

Just throwing another name in the mix. I'm highly interested in a ov5640 driver as well! The auto-focus is imperative for my use. Using OV2640 in the mean time, but i will be very interested in OV5640!

NairoDorian commented 4 years ago

Adding my name on the board of people who would thank you in the name of the community! If you have any numbers regarding the FPS count per resolutions on the maxed-out ESP32 WROVER for that OV5640? This could be huge

me-no-dev commented 4 years ago

you are not going to like the FPS much :) I'll prep a list. It depends on the XCLK (and seems other unrelated things, like v-flip). 5640 reacts much different than the other sensors and I find issues every day. PCLK output seems uncontrollable (apart from controlling XCLK) and because of ESP limitations, we can not push XCLK above 14MHz. The signals that I capture also look a bit weird when binning is enabled (scaling down the resolution). I'm currently expecting another sensor to arrive, just to make sure that all issues I see are or are not related to the sensors I currently have. So far, I have to say, 2640 is the best sensor. It's larger than both 3660 and 5640 and also has less pixels (which makes them bigger). FPS there is pretty good as well (and I'll try to pump some more)

ryanlimes commented 4 years ago

Thanks! @me-no-dev for writing the driver!

Waiting to try it out, ordered a 5640 AF, couldn't find a 3660 on aliexpress. Should arrive in 1 to 2 weeks time.

In my use case i'll just be taking photos with it rather than video, less concerned about the FPS but rather the higher resolution.

More than willing to help out with it if there's anything i can help with.

me-no-dev commented 4 years ago

this very repository now has ov5460 branch :) I'll push my latest attempts here to be synced. give it a shot.

Not sure how AF will work with glued lenses?

me-no-dev commented 4 years ago

Here is my test page. Change the IP on line 780 to what your ESP is and open if with your fav browser (I hope not IE).

ov5640_index.html.txt

me-no-dev commented 4 years ago

uhmm please note that the page has some features that are not implemented in the default web server examples. I use my Async server with Arduino as IDF component, so pasting the full code is pointless :) but you should be able to figure it out and extend the code that you use. In any case, here are the extra functions Async style:


void addCacheHeaders(AsyncWebServerResponse * response){
    response->addHeader("Cache-Control", "no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0");
    response->addHeader("Pragma", "no-cache");
    response->addHeader("Expires", "Mon, 24 Feb 2020 12:00:00 GMT");
}

void onReg(AsyncWebServerRequest *request){
    if(request->hasArg("reg") && request->hasArg("mask") && request->hasArg("val")){

        int reg = atoi(request->arg("reg").c_str());
        int mask = atoi(request->arg("mask").c_str());
        int val = atoi(request->arg("val").c_str());
        log_i("Set Register: reg: 0x%02x, mask: 0x%02x, value: 0x%02x", reg, mask, val);

        int res = 0;
        sensor_t * s = esp_camera_sensor_get();
        res = s->set_reg(s, reg, mask, val);
        if(res){
            log_e("Set register failed");
            request->send(501);
            return;
        }

        AsyncWebServerResponse * response = request->beginResponse(200);
        response->addHeader("Access-Control-Allow-Origin", "*");
        request->send(response);
        return;
    }
    log_e("Bad Arguments");
    request->send(404);
}

void onGreg(AsyncWebServerRequest *request){
    if(request->hasArg("reg") && request->hasArg("mask")){

        int reg = atoi(request->arg("reg").c_str());
        int mask = atoi(request->arg("mask").c_str());

        int res = 0;
        sensor_t * s = esp_camera_sensor_get();
        res = s->get_reg(s, reg, mask);
        if(res < 0){
            log_e("Get register failed");
            request->send(501);
            return;
        }
        log_i("Get Register: reg: 0x%02x, mask: 0x%02x, value: 0x%02x", reg, mask, res);
        const char * val = NULL;
        char buffer[20];
        val = itoa(res, buffer, 10);

        AsyncWebServerResponse * response = request->beginResponse(200, "text/plain", val);
        response->addHeader("Access-Control-Allow-Origin", "*");
        request->send(response);
        return;
    }
    log_e("Bad Arguments");
    request->send(404);
}

void onResolution(AsyncWebServerRequest *request){
    int res, reg4520, incrementX, incrementY, startX, startY, endX, endY, offsetX, offsetY, totalX, totalY, outputX, outputY, reg20, reg21, reg4514;
    bool scale;

    reg4520 = atoi(request->arg("reg4520").c_str());
    incrementX = atoi(request->arg("ix").c_str());
    incrementY = atoi(request->arg("iy").c_str());
    startX = atoi(request->arg("sx").c_str());
    startY = atoi(request->arg("sy").c_str());
    endX = atoi(request->arg("ex").c_str());
    endY = atoi(request->arg("ey").c_str());
    offsetX = atoi(request->arg("offx").c_str());
    offsetY = atoi(request->arg("offy").c_str());
    totalX = atoi(request->arg("tx").c_str());
    totalY = atoi(request->arg("ty").c_str());
    outputX = atoi(request->arg("ox").c_str());
    outputY = atoi(request->arg("oy").c_str());
    scale = atoi(request->arg("scale").c_str()) == 1;
    reg20 = atoi(request->arg("reg20").c_str());
    reg21 = atoi(request->arg("reg21").c_str());
    reg4514 = atoi(request->arg("reg4514").c_str());

    log_i("Set Resolution: 0x4520: 0x%x, Increment: 0x%x 0x%x, Start: %d %d, End: %d %d, Offset: %d %d, Total: %d %d, Output: %d %d, Scale: %u, reg20: 0x%x, reg21: 0x%x, reg4514: 0x%x", reg4520, incrementX, incrementY, startX, startY, endX, endY, offsetX, offsetY, totalX, totalY, outputX, outputY, scale, reg20, reg21, reg4514);

    sensor_t * s = esp_camera_sensor_get();
    res = s->set_res_raw(s, reg4520, incrementX, incrementY, startX, startY, endX, endY, offsetX, offsetY, totalX, totalY, outputX, outputY, scale, reg20, reg21, reg4514);
    if(res){
        log_e("Set resolution failed");
        request->send(501);
        return;
    }

    AsyncWebServerResponse * response = request->beginResponse(200);
    response->addHeader("Access-Control-Allow-Origin", "*");
    request->send(response);
}

void onPll(AsyncWebServerRequest *request){
    int res, bypass, mul, sys, root, pre, seld5, pclken, pclk;

    bypass = atoi(request->arg("bypass").c_str());
    mul = atoi(request->arg("mul").c_str());
    sys = atoi(request->arg("sys").c_str());
    root = atoi(request->arg("root").c_str());
    pre = atoi(request->arg("pre").c_str());
    seld5 = atoi(request->arg("seld5").c_str());
    pclken = atoi(request->arg("pclken").c_str());
    pclk = atoi(request->arg("pclk").c_str());

    log_i("Set Pll: bypass: %d, mul: %d, sys: %d, root: %d, pre: %d, seld5: %d, pclken: %d, pclk: %d", bypass, mul, sys, root, pre, seld5, pclken, pclk);
    sensor_t * s = esp_camera_sensor_get();
    res = s->set_pll(s, bypass, mul, sys, root, pre, seld5, pclken, pclk);
    if(res){
        log_e("Set resolution failed");
        request->send(501);
        return;
    }

    AsyncWebServerResponse * response = request->beginResponse(200);
    response->addHeader("Access-Control-Allow-Origin", "*");
    request->send(response);
}

void onXclk(AsyncWebServerRequest *request){
    int res, xclk;
    xclk = atoi(request->arg("xclk").c_str());
    log_i("Set XCLK: %d MHz", xclk);
    sensor_t * s = esp_camera_sensor_get();
    res = s->set_xclk(s, LEDC_TIMER_0, xclk);
    if(res){
        log_e("Set xclk failed");
        request->send(501);
        return;
    }
    AsyncWebServerResponse * response = request->beginResponse(200);
    response->addHeader("Access-Control-Allow-Origin", "*");
    request->send(response);
}
ryanlimes commented 4 years ago

uhhh the lens is glue-ed? -_- was hoping we can connect the pin and control it or something

using chrome lol not IE

Thanks! will look into it while waiting for the camera to arrive.

jjsch-dev commented 4 years ago

Good job @me-no-dev I tested the driver for the OV5660 in the esp32-camera-demo and work good. The pixel format was JPG and the size 800 x 600 pixels. In the next days I will test in RGB565 for QR recognition.

ov5660_1 ov5660_jpg

me-no-dev commented 4 years ago

Note that YUV and RGB might not yet work, since I found the proper PLL stuff, I have not tested the "raw" formats. Last night I worked on gamma to make the image "pop" and show more details. If you keep in sync with the branch, you can see the progress and maybe comment? I would love comments on the quality in different situations!

wero1414 commented 4 years ago

Hi @jjsch-dev I have a board made by hand but i dont get my camera detected and i dont really know if the problem is on my firmware or in my hardware would you mind to share your code?

jjsch-dev commented 4 years ago

Hi @wero1414, my code is in the esp32-cam-demo

jjsch-dev commented 4 years ago

Hi me-no-dev, I downloaded the new version and generate the following error. Screenshot from 2020-03-05 13-22-54

When I comment the following lines, the driver works

error_0x20003

I took the following images in JPEG format.

Screenshot from 2020-03-05 14-26-07 Screenshot from 2020-03-05 14-27-14 Screenshot from 2020-03-05 14-27-48

me-no-dev commented 4 years ago

@jjsch-dev yup I am aware :) figured it out last night. Have moved the reg writes to inside the main settings array and is all good now. weird.... will push the updates today.

@misghna should be all good :)

Currently I am adding controls to the different register blocks so that I/we can poke more into the settings and hopefully get a better image. I have to say... I do not like the 5640

jjsch-dev commented 4 years ago

@me-no-dev I fix the PLL for RGB565 and Gray, I uploaded the changes to my esp32-camera repository.

This are the changes that needs to be made in the OV5640 pll dirver.

pll_fix

And this is the change that needs to be made in the camera module.

gray_fix

The following photos are taken with these changes.

ov5660_gray_caba ov5660_rgb565

Celppu commented 4 years ago

I have two questions. What kind of framerates can be achieved with esp32 with ov5640? Any news on esp32-s2 and faster i2s?

jjsch-dev commented 4 years ago

Hi @Celppu, in my application the time to capture a frame in JPG in QVGA resolution is approximately 150 mS. But the video is very fluid when using jpg_stream. Tomorrow I will upload a sample video.

jpg_times

me-no-dev commented 4 years ago

frame rates depend on XCLK and on the aspect ratio of the chosen resolution. Wide screen resolutions are a bit faster, because there are less lines to scan. With that said, 1440p = 1080p = max 6FPS. 720p = 26FPS. The rest are slightly lower.

me-no-dev commented 4 years ago

@jjsch-dev that clock conf is a bit old now :) when I push the current settings, things will be different. Example:

    if (sensor->pixformat == PIXFORMAT_JPEG) {
        //10MHz PCLK
        uint8_t sys_mul = 200;
        if(framesize < FRAMESIZE_QVGA){
            sys_mul = 160;
        } else if(framesize < FRAMESIZE_XGA){
            sys_mul = 180;
        }
        ret = set_pll(sensor, false, sys_mul, 4, 2, false, 2, true, 4);
    }
jjsch-dev commented 4 years ago

@me-no-dev When you upload the new configuration I will try it. The zip contains two video captures in jpeg format.

(2881) camera_demo: Camera demo ready (7371) camera_demo: JPG Capture time 71317 uS, send time 6363 uS, total 77680 uS (10261) camera_demo: JPG Capture time 116382 uS, send time 6253 uS, total 122635 uS (10411) camera_demo: JPG Capture time 121663 uS, send time 21167 uS, total 142830 uS

ov5640_vga.mp4.zip

tototrix commented 4 years ago

Hi, Is it possible to get 5MP JPEG ( direct JPEG output from the OV5640) with your code ?

Best regards.

me-no-dev commented 4 years ago

@tototrix yes.

tototrix commented 4 years ago

@me-no-dev Thank you for your work. I'am trying to test your code but i encounter some issues. Is it possible to have some extra information about the right way to compile ( a tiny tutorial ).

I'am new with this environnement.

Best regards

jjsch-dev commented 4 years ago

@tototrix If you are going to use the camera demo application, you need to install the idf together with the bin tools. Espressif has a guide with the steps to install the idf on windows, linux and mac os. Before compiling the application, you need to copy the esp32-camera driver to the idf component directory.

tototrix commented 4 years ago

@jjsch-dev Thank you. Regarding to ESP version, which one should i use ?

me-no-dev commented 4 years ago

@tototrix you need to use a supported ESP32-Camera board (there are a few out there). ESP8266 can not work with cameras.

tototrix commented 4 years ago

@tototrix you need to use a supported ESP32-Camera board (there are a few out there). ESP8266 can not work with cameras.

I have the ESP-EYE board wich work pretty well. For my needs i want to get 5 MP photos with the OV5640 sensor. I have the OV5640 waveshare board.

Celppu commented 4 years ago

Is ov5642 compatible? Can exposure be controlled from the library to increase framerate?

jjsch-dev commented 4 years ago

@me-no-dev I Download your new March 11, 2020 version of OV5640.

Below I show you the captures in JPG format in VGA size. ov5660_11032020 ov5660_11032020_cup

This is a capture in RGB565 format in QQVGA size, with problems in the PLL.

ov5640_rgb565_error_bmp

me-no-dev commented 4 years ago

@jjsch-dev thanks for testing! All is fixed and support is now in master :) closing!!!

tototrix commented 4 years ago

Hi, I'am sorry but i'am still stucked with compilation.

With ESP-IDF41

First issue: the "CMakeLists.txt" file is missing from the project. I added it with the following content: image

When i tried ty compile i have the following error: image

So i decided to test with ESP-IDF40. My issues with ESP-IDF40:

First issue: the "CMakeLists.txt" file is missing from the project. I added it with the following content: image

Second issue: the app_main function is missing image

I added the file "CMakeLists.txt" into the main folder ... image

..with the following content image

This time the file "bitmap.h" is missing. I can find the file into the component folder (of the project) but i don't know how to solve the issue. image

Thanks in advance for your help. Best regards.

me-no-dev commented 4 years ago

something wrong with your project setup. Don't know what cam demo you are talking about... anyway, not an issue with the driver :)

tototrix commented 4 years ago

I speak about the following project: https://github.com/jjsch-dev/esp32-cam-demo

Have you an other one ?

me-no-dev commented 4 years ago

maybe you should ask there :) please do not create issues just to ask for examples ;) this is an issue tracker for issues with the driver and not with user issues.

jjsch-dev commented 4 years ago

Hi @tototrix sorry for the late answer. Today I updated the esp32-cam-demo repository with the CMakeLists.txt files. Until now I used make to compile in Ubuntu.

misghna commented 4 years ago

@me-no-dev well I got my board finally, do you mind if you can direct me to any doc or info on how I can add this driver to Arduino IDE (I see the repo [https://github.com/espressif/arduino-esp32/releases ] is last updated on Oct 2019) . Sorry for the hand holding here I am new to this ESP32 stuff :)

me-no-dev commented 4 years ago

@misghna if you are novice, you should wait for me to update the Arduino repo with the new driver. If you can not wait, https://github.com/espressif/esp32-arduino-lib-builder

misghna commented 4 years ago

novice

Okay, I will wait. I hope you will update it soon :) Thanks man

misghna commented 4 years ago

@me-no-dev, hi I have played with the ov5640 this week but I see vertical lines in the images(still-JPEG picture),and the problem magnifies as the resolution increases. I have tried two cameras, but unfortunately, the result is the same. Any idea why this is happening? the attached pictures are for UXGA and QSXGA (camera is 120 degrees wide)

test_picture_uxga test_picture_qsxga

me-no-dev commented 4 years ago

5640 really do not like less than perfect light :D Drop the XCLK to 10/15 MHz and they will dissapear

zell0323 commented 4 years ago

Hi, we have ported the OV5640 on our esp32-wrover-b. But we are suffering from a lot of noise, which doesn't appear on OV5642 with the same board. Any idea how to fix it? thanks! 圖片