×

INDI Library v2.0.7 is Released (01 Apr 2024)

Bi-monthly release with minor bug fixes and improvements

INDI LibCamera Driver

  • Posts: 74
  • Thank you received: 11

Replied by Anjo on topic INDI LibCamera Driver

Other neat tricks:

# connect a driver
pi@astrocam:~/astro/cam/libcamera-apps/build $ indi_setprop LibCamera.CONNECTION.CONNECT=On
# disconnect a connected driver
pi@astrocam:~/astro/cam/libcamera-apps/build $ indi_setprop LibCamera.CONNECTION.DISCONNECT=On
1 year 4 months ago #88710

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

Basically, at this point I wouldn't worry about EKOS. The primary target is to get several exposures and aborts working which can be done via the shell. When you're debugging, you can already see you're getting the correct exposure values.

All other things, like gain or whatever should be done by putting in a command line string in INDI via some generic LIBCAMERA_OPTIONS and parse that. Then you can quily test if things work.

After that, there should be UI for the individual options, but frankly, that's pretty tiresome work. Bla create prop, Bla create propP, bla parse INewFoo. Boooring.

The only interesting part is getting the whole thing to run - and hopefully more reliable than v4l2 and raspi...
1 year 4 months ago #88711

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

  • Posts: 124
  • Thank you received: 13

Replied by Outta on topic INDI LibCamera Driver

Finally I can help at least a bit, I do not know how ekos is translating RAW frames, that Jasem might know but I my self use this python script, but it uses openCV, i guess we can do it without that :):
I will redact code as I use openCV to detect object and crop it. This is used for PACKED mipi, for unpacked, we do not need this part of unpacking code.
    width = int(sys.argv[3])
    height = int(sys.argv[4])
    bayer_order = bayer_order_maps[sys.argv[5].lower()]
   img = unpack_mipi_raw10(remove_padding(data, width, height, 10)).reshape(height, width, 1)
   img = img >> 2
   img = img.astype(np.uint8)
   img = cv2.cvtColor(img, bayer_order)
   save_image(imgCrop, os.path.splitext(outputPath)[0] + ".tiff")
 
def unpack_mipi_raw10(byte_buf):
    data = np.frombuffer(byte_buf, dtype=np.uint8)
    # 5 bytes contain 4 10-bit pixels (5x8 == 4x10)
    b1, b2, b3, b4, b5 = np.reshape(
        data, (data.shape[0]//5, 5)).astype(np.uint16).T
    o1 = (b1 << 2) + ((b5) & 0x3)
    o2 = (b2 << 2) + ((b5 >> 2) & 0x3)
    o3 = (b3 << 2) + ((b5 >> 4) & 0x3)
    o4 = (b4 << 2) + ((b5 >> 6) & 0x3)
    unpacked = np.reshape(np.concatenate(
        (o1[:, None], o2[:, None], o3[:, None], o4[:, None]), axis=1),  4*o1.shape[0])
    return unpacked
 
def align_down(size, align):
    return (size & ~((align)-1))
 
def align_up(size, align):
    return align_down(size + align - 1, align)
 
def remove_padding(data, width, height, bit_width):
    buff = np.frombuffer(data, np.uint8)
    real_width = width // 8 * bit_width
    align_width = align_up(real_width, 32)
    align_height = align_up(height, 16)
    if(height == 1080):
        align_height=1080
 
    buff = buff.reshape(align_height, align_width)
    buff = buff[:height, :real_width]
    buff = buff.reshape(height * real_width)
    return buff
 
 
def save_image(img, name):
    cv2.imwrite(name, img, params=(cv2.IMWRITE_TIFF_COMPRESSION,1))
 
1 year 4 months ago #88719

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

  • Posts: 115
  • Thank you received: 34

Replied by Simon on topic INDI LibCamera Driver

Yeeeeee, OUTTA I'm glad that you solved issues with your device. I think we are making good progress here. I'm can't wait to put my HQ cam finnaly to test under clear skies and do some long exposure test! :D
1 year 4 months ago #88720

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

There's already code in libcamera-app to create dng, though, which are to my knowledge some "standard" raw format.

Check out dng_save in libcamera-apps/image/dng.cpp.

I played around some more and in theory I guess using one app should work.

There seem to be mixups between what libcamera threads and indi threads are doing. Also, startPreview seems to get called even when you give it nopreview in the options.
1 year 4 months ago #88721

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 added your code to my fork, but it gives me the "full frame", ie 1937xsomething and not 1920x1080 as it should?

github.com/indilib/indi-3rdparty/compare...i-3rdparty:libcamera

Also, I think we should just copy over the libcamera-app code verbatim like it was done before with the includes. I just don't know how to get the top level to also build the sublevel? Then we shouldn't need to make install or anything of the libcamera-apps, potentially overwriting system stuff.

When things work, we can pull out the bits we need into the driver and remove the apps code, but I'm not sure it's worth the effort.

For now, getting repeatable exposures to work should be the first prio.
Last edit: 1 year 4 months ago by Anjo.
1 year 4 months ago #88722

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

  • Posts: 115
  • Thank you received: 34

Replied by Simon on topic INDI LibCamera Driver

@Anjo: That's wierd! For my sensor imx477 it returns correct values. What about pixel size? Is that correct?
Last edit: 1 year 4 months ago by Simon.
1 year 4 months ago #88723

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

Yeah px size is correct. There's 2 bounds in the profiles, I guess this is the wrong one? PixelArrayActiveAreas vs PixelArraySize?

extern const std::array<const ControlValue, 3> LocationValues;
extern const Control<int32_t> Location;
extern const Control<int32_t> Rotation;
extern const Control<std::string> Model;
extern const Control<Size> UnitCellSize;
extern const Control<Size> PixelArraySize;
extern const Control<Span<const Rectangle>> PixelArrayOpticalBlackRectangles;
extern const Control<Span<const Rectangle>> PixelArrayActiveAreas;
extern const Control<Rectangle> ScalerCropMaximum;
extern const Control<float> SensorSensitivity;
1 year 4 months ago #88724

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

OK, the livecycle seems to work now. You can turn on/off exposures and streams multiple times without it crashing.

The trick is that you need to:

- configure
- start encoder (with videos, possibly also with stills)
- start camera
...
- stop camera
- teardown
- stop encoder

I also added libcamera-apps code in full. Still not sure how it should build, though.

This is the last time I'll be showing this link. In the future we need to come up with a more sensible way to exchange code:

github.com/indilib/indi-3rdparty/compare...i-3rdparty:libcamera

I still get "unknown bayer format" when exposing and a mostly black screen when showing the stream in kstars.

Also, you need to re-make install libcamera-apps whenever you make a change in the core stuff.

It would be nice of someone with more knowledge of CMake could take a look and fix up things so they build libcamera-apps as part of the driver build and take the includes from there.
Last edit: 1 year 4 months ago by Anjo.
1 year 4 months ago #88730

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

  • Posts: 124
  • Thank you received: 13

Replied by Outta on topic INDI LibCamera Driver

@Jasem can you create libcamera dev branch and give access for few of us so we can freely push and then we can do PR when we have something.
1 year 4 months ago #88732

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

Replied by Jasem Mutlaq on topic INDI LibCamera Driver

What do you mean libcamera dev branch? Each project has their own repos. You indi indi-libcamera driver? you can fork that. We're using libraw to decode any raw files, I already implemented that in the driver.
1 year 4 months ago #88741

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

  • Posts: 115
  • Thank you received: 34

Replied by Simon on topic INDI LibCamera Driver

Anjo, I have never use it before, but I thing git submodules could help you with that: git-scm.com/book/en/v2/Git-Tools-Submodules
1 year 4 months ago #88743

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

Time to create page: 1.229 seconds