Help with development (Coding Doubts)

Started by Alex_Palomo, January 24, 2017, 04:35:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Alex_Palomo

Hy guys, I am starting this new topic in order to solve some specific coding doubts that I have. Maybe this thread does not respect the ML forum rules, or maybe yes, but I think that it could help. I'm currently working on a new feature for ML but I am not an expert on programming it. I am on my last degree on informatic/audiovisual year and I've learned how to code, but ML is huge and I am lost sometimes.

Here are my current doubts:

1. It is possible to access the image buffer of the camera when we are not recording? And when we are recording?

2. It is possible to save a sequence of photos on the memory RAM of the camera or on the SD card and then read it from there? I explain you the problem - My purpose is to take some pictures, save them on the memory, then perform some computations with these images and then use the result (reading it from the memory) to apply a concret method.

Thank you all, and I hope that this could help.
Let's keep ML high.

Licaon_Kter

You know you have very little memory to work with, right?

Read from post #30 onwards: http://www.magiclantern.fm/forum/index.php?topic=5071.msg166799#msg166799

Also, could you do this (whatever you want) from LUA scripting instead? (memory limitated still)

Alex_Palomo

Thanks for your time Licaon_Kter!
What is the advantage of using Lua?


dmilligan

For temporary uses like image processing there is actually quite a huge amount of memory available (you may need to use the memSuites rather than a simple malloc call, see raw_rec.c or mlv_rec.c)

The memory limitation is mainly for permanently wired stuff like executable code and data that needs to persist the entire time the camera is on.

Lua cannot currently do image processing.

To answer OP's original questions:

1. Yes

2. Yes, see silent.c for how to capture and save LV or FRSP image buffers, or have a look at ettr.c for how to also capture and do some processing on LV or QR image buffers. Also see raw.c for some of the lower level routines that are used by these modules.

Note:
We have recently been learning more about the hardware image processing capabilities in the cameras and depending on exactly what you are trying to do, it may be possible to utilize those capabilities see: http://www.magiclantern.fm/forum/index.php?topic=13408.0 . Keep in mind that if you don't use hardware modules for processing, your code may run quite slowly, the CPUs in these cameras are quite slow. For example even something as simple as reversing the endianess of the image buffer for saving DNG can take on the order of seconds (using Canon compression hardware for DNG writing is on the order of 10s of milliseconds: http://www.magiclantern.fm/forum/index.php?topic=18443.msg176631#msg176631)

Alex_Palomo

Such a good new to read your post dmilligan !!!  :) It is amazing to receive such help from experts, you are helping me a lot.
Now I'm working on LUA, trying to understand how to use it. I've loaded the lua.mo module, but when I reboot the camera the following message appears:

QuotePANIC: unprotected error in call to Lua API (not enough memory) abort

Does it mean that the SD card memory is not enough? How can I solve it?

Thank you again guys!


dmilligan

It's talking about RAM, not SD. Either delete some or all of the built in scripts from the SD card or try using an experimental Lua build from here: https://builds.magiclantern.fm/experiments.html

Alex_Palomo

Actually, I've format the SD card from the camera (Is that what you mean by saying delete some or all of the built in scripts from the SD card ?). Then, I just install ML and load lua.mo and this error appears.

dfort

On the SD card there is an ML folder and in that folder is a "scripts" folder with a bunch of lua files. Delete the scripts that you are not going to be using.

Alex_Palomo

Thank you dfort!!! I'll be updating this post so that to keep you all informed.  :)

Alex_Palomo

Hy! It's me again.
I'm trying to call the focus function from lens library (LUA) and I get syntax error every time. I've searched for it on the LUA API and I've found this:

focus (num_steps[, step_size=2[, wait=true[, extra_delay=0]]])

and this:

lens.focus(steps,[step_size],[wait],[extra_delay]

I don't think it is correct...I've proved and it is not working. How do I have to call the function?
Thank you.

garry23

@Alex_Palomo

This format is OK, ie move towards infinity (at least on my lenses) 1 step (-1) using step size 1.

Best guidance is use true rather than false.


lens.focus(-1,1,true)

Alex_Palomo

Hy guys! I have some problems with the movie.start() LUA function. I just call it when I press "Start Video" on the submenu but it just only goes to LiveView without recording:


I thought that it would be an easy problem to solve, but I don't know why it does not work.
Hope you can help me. Thank you.

Alex_Palomo

Hy guys!
1. Do you know if I can decide wherever a photo is saved when executing camera.shoot() (LUA Scripting)?
2. Can I read from the SD card (or any memory on the camera) with LUA?
Thank you!

dmilligan

1.

string.format("DCIM/%03dCANON/%s%04d.CR2", dryos.shooting_card.folder_number, dryos.prefix, dryos.shooting_card.file_number)


2. Use io library: https://www.lua.org/manual/5.3/manual.html#6.8

Trying to read from or write to a CR2 file from Lua may not be the best idea. What are you trying to do?

Alex_Palomo

Thank you dmilligan!
I just want to (in this order):
1.Take some photos
2.Read them from the SD card and then save them in different variables
3.Once I have the images, then perform some image processing (obviously I need to work with matrices)
4....


garry23

@Alex_Palomo

Alex I have PMed you replies several times.

Based on what you say below, I don't see any complications.

Lua will allow you to robustly take an image when you want, ie at a specified exposure or at a specified focus point (as I said to you have a look at others' scripts for ideas).

After that it is simply 'PC-based' post processing, eg reading the image file, either a CR2 or a DNG or even a MLV file, into your PC(/MAC).

Cheers

Garry

Alex_Palomo

Hy garry23, I will work on it!
Again thank you for your time.

Alex_Palomo

I'm actually working on the src file focus.c and I need to use two methods:

1. A method to take a photo
2. A method to move the focus (Do LensFocus or LensFocus2 move the focus?)

Which ones do you know?
Thank you.

garry23

Why are you going to the .c area of ML?

I thought you wanted to script?

If so, read everything here https://davidmilligan.github.io/ml-lua/modules/camera.html#shoot, including the demo scripts.

Cheers

Garry


Alex_Palomo

Hy guys!
How can I capture the data on the image buffer? I mean, I need to save the image seen by the sensor on a certain moment. Is that even possible?
Thank you.

dmilligan

The "raw backend" (raw.c/.h) has functions for that. For examples see modules/silent/silent.c

Alex_Palomo

Hy guys! I'm trying to load my own module, but every time I try to load it on the camera it fails and the following occurs:



Before loading the module, the README file is correctly read and displayed on the screen.

Hope you can help me! Thank you!

Walter Schulz

Link to your repository (and therefore source) would be helpful, I think!

Alex_Palomo


Walter Schulz

Well, that's not what I meant and I don't think this kind of information sharing (or not sharing) is the best way to get help.

Alex_Palomo

Here is part of the code:


#include <dryos.h>
#include <menu.h>
#include <bmp.h>
#include <lens.h>
#include <config.h>
#include <shoot.h>
#include <math.h>
#include <lvinfo.h>
#include <focus.h>
#include <property.h>
#include <module.h>

static int step_size = 1;
static float apertures_vector[] = {3.5, 4.0, 4.5, 5.0, 5.6, 6.3, 7.1, 8.0, 9.0, 10, 11, 13, 14, 16, 18, 20, 22};

static void dualBracketing()
{
//If lens.focus_distance is not at 250mm (closer focus/init position), then reset focus to init position.
if (lens_info.focus_dist > 25)
{
while (lens_info.focus_dist > 25) lens_focus(1, 3, 1, 1*10);
}
//Dual Bracketing loop
while (lens_info.focus_dist < lens_info.hyperfocal)
    {
for(int i = 0; i < 17; i++)
{
lens_set_rawaperture(apertures_vector[i]); //Set aperture
lens_take_picture(64,false); //Take a picture
/*msleep(100); //sleep for 100ms
if (!lv) force_liveview(); //start LiveViev if turned off*/
}
lens_focus(-1, step_size, 1, 1*10); //Establir quin és el step_size òptim-->Quantes fotos necessitem per calcular depth map?
       //step_size = 1 --> X photos
      //step_size = 2 --> X photos
     //step_size = 3 --> 6 photos
}
}

static int num_proba = 0;
static void proba()
{
lens_set_rawaperture(apertures_vector[num_proba]);
}

static struct menu_entry dualBr_menu[] =
{
    {
        .name = "Dual Bracketing",
.help = "Focus + Aperture Bracketing.",
.help2 = "Press Q to see the options.",
.depends_on = DEP_AUTOFOCUS,
.children =  (struct menu_entry[]) {
            {
                .name = "Start Bracketing",
.priv = dualBracketing,
        .select = run_in_separate_task,
                .help  = "For each step focus, does an aperture bracketing",
.help2 = "Press SET to start taking photos.",
            },
{
                .name = "Step Size",
                .priv = &step_size,
                .min = 1,
                .max = 5,
                .help  = "Size of the focus step",
                .help2 = "The smaller it is, the more pictures it take",
            },
{
                .name = "Proba",
.select = proba,
            },
{
                .name = "num_proba",
                .priv = &num_proba,
                .min = 0,
                .max = 16,
            },
MENU_EOL,
},
    },
};

static unsigned int dualBr_init()
{
menu_add("Shoot", dualBr_menu, COUNT(dualBr_menu));
    return 0;
}

static unsigned int dualBr_deinit()
{
    return 0;
}

MODULE_INFO_START()
    MODULE_INIT(dualBr_init)
    MODULE_DEINIT(dualBr_deinit)
MODULE_INFO_END()


Maybe I'm forgetting to put some code so that to get the module working.

a1ex

After compiling, your module load just fine here, without any changes.

Alex_Palomo

Do I have to add my module on Makefile.modules.default or anywhere?

a1ex

I've created a directory under modules/, pasted your code in a .c file, copied Makefile from ettr and changed the name. Running "make" created a template README.rst, which I didn't change. Then, "make install" to copy the module to the card. Loaded the module, it showed OK and a new menu entry appeared under Shoot.

Didn't touch Makefile.modules.default.

mk11174

I had this happen back in the days i played around, first start camera, unload the module, shut down camera, check card for duplicate modules by showing hidden files look for a version with a ~ in the module name, delete it if its there, also delete the cfg file related to your module if there  is one. Then restart camera and enable module, then restart camera again to see if it loads.
500D/T1i  550D/T2i  600D/T3i  700D/T5i

Alex_Palomo

Wow! Thank you a1ex and mk11174 it's so good to get feedback from you, I'm so greateful.

mk11174 I tried it but there isn't any hidden file starting with ~. It looks good for me.(Maybe I'm wrong)

I thing that the problem comes from the way I create the ML folder to be copied on the card. Here is how I proceed:

1.I write the following lines in the terminal:

cd test/magic-lantern
make -j2
cd platform
cd 600D*
make zip


2.After it ends compiling I copy the ML folder that has been created on the 600D platform, into the card.

3.Then insert de card on the camera and install ML.

4.Then open the MODULES menu and my module is not there. (The only way to get my module on MODULES menu is by modifying the Makefile.modules.default file)

Am I proceeding wrong? Why my module does not load without having to modify the Makefile.modules.default file?

Thanks for your time guys!

mk11174

If your not making the module from the actual module folder then it wont remake it as far as i remember, thats why you modify the default file so when you make it from the platform folder for your model it will remake it. So modify the default file, then run a make clean from the modules main folder to clean everything up first, then rmake your 600d from the platform and camera model folder, but i would also make clean that one to just to clean everything up.

Also delete ml folder and bin file from card to start fresh there to so you are only using modules from your compiled source.
500D/T1i  550D/T2i  600D/T3i  700D/T5i

Alex_Palomo

Yeah!!! It is working now! Many many thanks guys! You have been a great support :)

Alex_Palomo

Good afternoon, there is menu dependency for the Av mode? (Something like DEP_AV_MODE or similar)

Thank you:)

a1ex

Nope, but the list (from menu.h) is open. Or, you can use a MENU_WARN_NOT_WORKING.

Alex_Palomo