×

INDI Library v2.0.6 is Released (02 Feb 2024)

Bi-monthly release with minor bug fixes and improvements

INDI LibCamera Driver

Replied by Jasem Mutlaq on topic INDI LibCamera Driver

There is already a queue actually and you can see it creating a thread from the preview thread pool . If you can make this operation more efficient, then that's great!
1 year 3 months ago #88813

Please Log in or Create an account to join the conversation.

  • Posts: 106
  • Thank you received: 33

Replied by Simon on topic INDI LibCamera Driver

@Anjo, that's awsome progress! I'll try to checkout your branch and build it by your instruction as soon as I can.
1 year 3 months ago #88827

Please Log in or Create an account to join the conversation.

  • Posts: 74
  • Thank you received: 11

Replied by Anjo on topic INDI LibCamera Driver

Either I'm too stupid or the options parsing is broken (as it was from the beginning, btw).

This here prints totally weird values and even crashes. Any Idea why?

<code>
static int parseArgs(char *str, char *delim, char **argv, int max)
{
int argc = 0;
char* token = strtok(str, delim);
argv[argc++] = token;
while (token != NULL) {
token = strtok(NULL, delim);
argv[argc++] = token;
if(max < argc) {
break;
}
}

return argc-1;
}

static void doArgs(char *str)
{
Options option = StillOptions();
printf("-->\n");
char *argv[64] = {};
char delim[] = " \t\n";
int argc = parseArgs(str, delim, argv, sizeof(argv));
printf("%d\n", argc);
for(int i = 0; i < argc; i++) {
char *token = argv;
printf("0x%8lx >%s<\n", token, token);
}
option.Parse(argc, argv);
option.Print();
printf("--<\n");
}

INDILibCamera::INDILibCamera()
{
char str1[] = "--config /tmp/config.txt";
doArgs(str1);
...
</code>

The config file contains this, but that doesn't really matter- even when you give a normal args string, you just get a garbage Options:

<code>
pi@astrocam:~/astro/indi-3rdparty/build/indi-libcamera $ cat /tmp/config.txt
-n -t 0 -o - --awbgains 1,1 --immediate
</code>
Last edit: 1 year 3 months ago by Anjo.
1 year 3 months ago #88843

Please Log in or Create an account to join the conversation.

  • Posts: 106
  • Thank you received: 33

Replied by Simon on topic INDI LibCamera Driver

@Anjo, can you put link here to your development branch, so that I can test the code?
1 year 3 months ago #88855

Please Log in or Create an account to join the conversation.

  • Posts: 74
  • Thank you received: 11

Replied by Anjo on topic INDI LibCamera Driver

github.com/anjok/indi-3rdparty/tree/libcamera

If you send me your github nick, I can add you as a collaborator.
1 year 3 months ago #88867

Please Log in or Create an account to join the conversation.

  • Posts: 123
  • Thank you received: 13

Replied by Outta on topic INDI LibCamera Driver

Inhave been testing Anjos brilliant work with IMX462.

I got exposure and I got streaming!

Although it is limited to 640x480, and only jpeg stills. DNG says "unknown bayer format" trying to debug that.

I see there are modes added manually, I think we can pull them from libcamera, same way as libcamera-vid - - list-cameras work.
All in all it is great to see exposure and stream work!
Last edit: 1 year 3 months ago by Outta.
1 year 3 months ago #88878

Please Log in or Create an account to join the conversation.

  • Posts: 74
  • Thank you received: 11

Replied by Anjo on topic INDI LibCamera Driver

First of all, lets all thank Jasem to get this thing started in the first place. I just fixed a few things :)

The unknown bayer is because it's not a raw stream, but a yuv420 stream instead.

The 640x480 is because the width and height are never set and so they use the default - like everything else They should be set from the respective number properties in the Indi:CCD. Note that subframing would need to be translated from XY to 0..1x0..1, btw

I still think it would be faster if someone found out why the args parsing doesn't work. I don't have time for that right now, though.

That way, we could quickly try out various settings without needing to create UI for it. Eg, do you know what "gain" or "rotation" should be named like to get it recognized by ekos? And there's no libcamera-util --list-controls where you could find out about them like there is for v4l2.

I would prefer if there were two text files, "video.conf" and "still.conf" (maybe setable by indi props) that would be used as the config templates and then gradually add UI for the rest. You can't hardcode the values, since all cams will be different and testing out these values has been a bitch so far.

Picking things out of the apps is nice, but costs time that could be better spent on other things.

For later, I would really like in-app stacking - in particular for video - like the v4l2 client partially does.

Also note that to get a reasonable stream, you first need to expose for some reason. Dunno why.
The following user(s) said Thank You: Jasem Mutlaq
1 year 3 months ago #88884

Please Log in or Create an account to join the conversation.

  • Posts: 74
  • Thank you received: 11

Replied by Anjo on topic INDI LibCamera Driver

Actually, we should probably just subclass/copy our own LibcameraIndiApp for now in the indi part of the code.
1 year 3 months ago #88885

Please Log in or Create an account to join the conversation.

  • Posts: 27
  • Thank you received: 4
First of all many thanks for working on this. I am really impressed by the progress you made!

I made some experiments in Python, mainly to understand:
  • how libcamera works,
  • how to select and configure a camera,
  • what is needed to get raw data and what format it has,
  • how to configure libcamera for fast exposure (running the next exposure while the actual one gets processed and transmitted to client) and
  • if libcamera can do very long exposures and how to switch between exposure times.

I did this on a Raspberry Pi Zero with HQ camera (the hardware I use for astro photography). Attached are the Python code and its output.Maybe it can help you to implement the libcamera staff or to make own experiments.
The following user(s) said Thank You: Jasem Mutlaq
1 year 3 months ago #88962
Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 74
  • Thank you received: 11

Replied by Anjo on topic INDI LibCamera Driver

I would like to, but can't :(

sudo apt-get -y install libcap-dev python3-libcamera
pip install picamera2

libcamera-hello
->
[24:45:34.494209213] [24736] INFO Camera camera_manager.cpp:299 libcamera v0.0.2+47-0684c373

then

python
Python 3.9.2 (default, Mar 12 2021, 04:06:34)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> import datetime
>>> import pprint
>>> from picamera2 import Picamera2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/.local/lib/python3.9/site-packages/picamera2/__init__.py", line 5, in <module>
from .picamera2 import Picamera2, Preview
File "/home/pi/.local/lib/python3.9/site-packages/picamera2/picamera2.py", line 21, in <module>
from picamera2.encoders import Encoder, H264Encoder, MJPEGEncoder, Quality
File "/home/pi/.local/lib/python3.9/site-packages/picamera2/encoders/__init__.py", line 3, in <module>
from .jpeg_encoder import JpegEncoder
File "/home/pi/.local/lib/python3.9/site-packages/picamera2/encoders/jpeg_encoder.py", line 3, in <module>
import simplejpeg
File "/home/pi/.local/lib/python3.9/site-packages/simplejpeg/__init__.py", line 1, in <module>
from ._jpeg import encode_jpeg
File "simplejpeg/_jpeg.pyx", line 1, in init simplejpeg._jpeg
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 48 from C header, got 40 from PyObject
1 year 3 months ago #89137

Please Log in or Create an account to join the conversation.

  • Posts: 3
  • Thank you received: 1
Hello, I'm very impressed with this thread.

Regarding the options parsing, It seems that option variable has to be created in the context of Libcamera Encoder(). ( I'm learning and my C++ is rusty so I apologize in advance)

The following code snipet works for me:
<code>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

vector<string> split(string str, char delimiter) {
vector<string> out;
stringstream ss(str);
string token;
while(getline(ss, token, delimiter)) {
out.push_back(token);
}
return out;
}

int getArgv(char** argv, string str) {
vector<string> splitStr = split(str, ' ');
for (long unsigned int i = 0; i < splitStr.size(); i++) {
argv = new char[splitStr.length() + 1];
strcpy(argv, splitStr.c_str());
}
return splitStr.size();
}


INDILibCamera::INDILibCamera()
{
// char str1[] = "-n -t 0 -o -\n --awbgains 1,1 --immediate -v 2";
char str1[] = "-n -t 0 -o -\n --awbgains 1,1 -v 2 --width 1920 --height 1080";
char *argv[64] = {};
int argc = getArgv(argv, str1);


setVersion(LIBCAMERA_VERSION_MAJOR, LIBCAMERA_VERSION_MINOR);
signal(SIGBUS, default_signal_handler);
//m_StillApp.reset(new LibcameraApp(std::make_unique<StillOptions>()));

LibcameraEncoder *lib_cam_enc = new LibcameraEncoder();
VideoOptions *options = lib_cam_enc->GetOptions();


if (options->Parse(argc, argv))
{
if (options->verbose >= 2)
options->Print();
}


m_StillApp.reset(lib_cam_enc);
m_VideoApp.reset(m_StillApp.get());
}
</code>

Note: Because of my rusty c++, I used ChatGPT to create functions getArgv() and split(). Is that ok?
The following user(s) said Thank You: Jasem Mutlaq
Last edit: 1 year 3 months ago by Joaquin Barcelo. Reason: Adding note about how functions where created
1 year 3 months ago #89152

Please Log in or Create an account to join the conversation.

  • Posts: 27
  • Thank you received: 4
@ANJO
It seems some Python dependencies are broken. I installed pycamera2 with "sudo apt-get" and not with pip:
sudo apt-get python3-picamera2

The "simplejpeg" library that fails in your system comes from package "python3-simplejpeg" on my Raspberry Pi. Maybe you need to reinstall it too with "sudo apt-get". Maybe you will also need an upgrade/update of the whole system.
1 year 3 months ago #89169

Please Log in or Create an account to join the conversation.

Time to create page: 1.592 seconds