VC-MIPI-modules / vc_mipi_nvidia

Vision Components MIPI CSI-2 driver for NVIDIA Jetson Nano, Xavier NX, AGX Xavier, TX2 and Orin Nano, Orin NX
75 stars 31 forks source link

IMX264 sensor not accepting colors correctly. #116

Open hseysen opened 3 weeks ago

hseysen commented 3 weeks ago

I'm using NVIDIA Jetson Nano with L4T 32.7.4 and IMX264 camera sensor. I have configured the .dtsi file and I can successfully obtain an image using nvarguscamerasrc using GStreamer, and also argus_camera using the jetson_multimedia_api. However, I visually see that the camera does not recognize the colors correctly.

I've tried to write a Python script using OpenCV, and here is the code:

import cv2

cap = cv2.VideoCapture("/dev/video0", cv2.CAP_V4L)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 2432)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 2048)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('R', 'G', 'G', 'B'))
cap.set(cv2.CAP_PROP_CONVERT_RGB, 0)

if not cap.isOpened():
    print("Error: Failed to open camera.")
    exit(1)

image_id = 0
while True:
    ret, frame = cap.read()
    print(frame.shape)
    print(frame.dtype)
    frame = frame.reshape((2048, 2432))
    if not ret:
        print("Error: Failed to grab frame.")
        continue
    frame = cv2.cvtColor(frame, cv2.COLOR_BAYER_RG2RGB)

    frame_resized = cv2.resize(frame, (608, 512))
    cv2.imshow("Frame", frame_resized)

    key = cv2.waitKey(1) & 0xFF
    if key == ord('q'):
        break
    elif key == ord('c'):
        cv2.imwrite(f"capture{image_id}.png", frame)
        print(f"Image captured as: capture{image_id}.png")
        image_id += 1

cap.release()
cv2.destroyAllWindows()

Here is the image I put up on my phone's screen: https://m.media-amazon.com/images/I/71Icb3wd6DL.jpg Here is the image captured: https://imgur.com/loQ30Bh

The script gives me a rather darker image, the nvarguscamerasrc pipelines give me a brighter view. Maybe I'm missing something on the OpenCV script.

hseysen commented 3 weeks ago

I also have an IMX566 camera sensor available to me, for which I just changed the .dtsi settings for, and can confirm that it can distinguish colors correctly. This might be something related to the IMX264 sensor? Or perhaps that is the intended behavior, some kind of limitation on the perceived colors?