How to manually set the camera white balance using Ketai?

Is there any way to manually set the white balance using Ketai? I know it has the manualSettings() method but it does virtually nothing for setting things manually, it just disables automatic setting changes by the system.

I’ve tried doing it using android.hardware.camera2 but that’s far beyond my current skills as I have no deep knowledge of the Android platform (thus why using Processing, anyways :slight_smile: )

My phone certainly supports manual white balance as it works in several camera apps.

**Disclaimer: This is not a solution to your question, but perhaps will help you understand how to start to use android.hardware.camera2.

/*
  Sketch Permissions: BIND_CONTROLS, CAMERA checked
 */

import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.CaptureRequest.Builder;
import android.hardware.camera2.CaptureResult;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CaptureRequest.Key;
import android.os.Parcelable;
import android.content.Context;

public static final int CONTROL_AWB_MODE_AUTO = 0;
public static final int CONTROL_AWB_MODE_OFF = 1;
public static final int CONTROL_AWB_MODE_DAYLIGHT = 1;
public static final int CONTROL_AWB_MODE_SHADE = 1;
public static final int CONTROL_AWB_MODE_CLOUDY_DAYLIGHT = 0;
public static final int CONTROL_AWB_MODE_INCANDESCENT = 0;
public static final int CONTROL_AWB_MODE_FLUORESCENT = 0;
public static final int CONTROL_AWB_MODE_WARM_FLUORESCENT = 0;
public static final int CONTROL_AWB_MODE_TWILIGHT = 0;
public static final int CONTROL_AWB_STATE_LOCKED = 1;
public static final int CONTROL_AWB_STATE_CONVERGED = 1;

CameraManager manager;
CameraDevice camera;
Context context;
CameraMetadata metadata;

void setup() {
  fullScreen();
  manager = (CameraManager)this.getContext().getSystemService(Context.CAMERA_SERVICE);
  println(manager);

  try {
    printArray(manager.getCameraIdList());
  }
  catch (CameraAccessException e) {
    println(e);
  }
  println(CONTROL_AWB_MODE_OFF);
  println(CONTROL_AWB_MODE_SHADE);
}

void draw() {
  background(70, 80, 220);
}

1 Like

Hi

I think that first you have to know about image and filters this is simple explanation about that from our great teacher @hamoid

https://funprogramming.org/89-Create-your-own-photo-filters.html

https://funprogramming.org/90-Change-pixel-hue-saturation-and-brightness.html

Then you have to get an idea about White balance this how in Photoshop

This could be good start for you

Well, I am not new to the processing. I’ve been using it for a few years now and I know what PImage, Pixels, WB, filters and so on are. This is not the problem. I could clearly post-process the image and change the white balance normally.

But in this case I work with some quite low light setup and when the camera is allowed to set WB automatically the quality of the image is not what I like to get and post-processing helps not much. This is because first the Android system applies it’s own changes to the pixels and then serves me the image data already altered.

This is why I’d like to set the WB before I get the image data from the Android software.

Anyway – thanks for the sources you have provided. It might halp someone anyways.

Thanks, I’ll try to dive into it. Won’t there be a conflict between the Ketai and the CameraManager if I use them both together?

Also as I understand setting the CONTROL_AWB_MODE_* finals has something to do with choosing the AWB mode, am I correct? Many camera apps allow to set WB manually using a slider with the temperature scale. Is there any setting in CameraManager that allows to do this?

Regards!

Thank you for the clarification which is what I surmised from your initial post. Unfortunately I am not an expert in this area and don’t want to give you false information. I have no experience with Ketai and have no idea if it would play nice with the CameraManager. I’ve spent a fair amount of time reading the documentation for Android code and don’t recall seeing anything that would allow a user to set the white balance with a slider. I _think we would have to turn off the auto mode feature and set the white balance for one of the constants, eg Daylight, Shade, Cloudy Daylight, Incandescent, Fluorescent, Warm Fluorescent, Twilight, etc. What is unclear to me is whether we can do this by just setting the initial value to 0 or 1 or whether we have to use a getter/setter combination, ie check to see what it is set to by default and then reset it to something else before the image is taken. I spent several hours trying to get manager.openCamera() to work and failed because I did not setup the callback and handler correctly. I would also like to be able to get more metadata about camera settings before taking the image. I presume that you have already seen the following documenation.

https://developer.android.com/reference/android/hardware/camera2/CameraManager
https://developer.android.com/reference/android/hardware/camera2/CaptureRequest#CONTROL_AWB_MODE

Hi
@outslider for your knowledge see this code

//Code by @akenaton

import android.app.Activity; 
import android.content.Intent; 
import android.provider.MediaStore; 

public static final int LAUNCH_CAM = 1; 

public void setup() { 
  orientation(LANDSCAPE); 
  Intent intent= new Intent(MediaStore.INTENT_ACTION_VIDEO_CAMERA); 
  getActivity().startActivityForResult(intent, LAUNCH_CAM);
}

@outslider hi again
It’s away from your demand but I want to say about my experiment
Once I made project with processing PC mode I used video library then I got an idea to make it with android mode the video library was not compatible with Android mode and ketai library didn’t accept the sketch as video library with hard work and searching I could do it by mixing both in one and it’s successful