SOLVED: Check for THETA SC2 auto bracket completion

,

Hi,
I’m working on an app that can take automated brackets for hdr but I’m currently blocked because when calling “camera.startCapture” it never end.
right now, I do setOptions with

{
   "_autoBracket":  {
    "_bracketNumber":4,
    "_bracketParameters": [
  {
    "shutterSpeed":0.05,
    "iso":64,
    "whiteBalance":"auto"
  },
  {
    "shutterSpeed":0.07692307,
    "iso":64,
    "whiteBalance":"auto"
  },
  {
    "shutterSpeed":0.2,
    "iso":64,
    "whiteBalance":"auto"
  },
  {
    "shutterSpeed":0.33333333,
    "iso":64,
    "whiteBalance":"auto"
  }
  ]
}
}

that is working, then I’m calling startCapture with _mode:‘bracket’
then when following the capture status, I receive something like that

{"id": "5136", "name": "camera.startCapture", "progress": {"completion": 75}, "state": "inProgress"}
{"id": "5136", "name": "camera.startCapture", "progress": {"completion": 0}, "state": "inProgress"}
{"id": "5136", "name": "camera.startCapture", "progress": {"completion": 0}, "state": "inProgress"}

So basically it take all the pictures of my brackets, the progression is working too, but then it just go back to completion 0 and I never receive state done, it just stay “inProgress” forever.
I’m I missing an option or doing it wrong? I don’t really understand.
My SC2 is on the latest firmware (1.31)
Thanks!

Using /osc/command/status with the id received on startCapture didn’t work, state is always inProgess but I found a way to bypass that looking at /osc/state and waiting for _captureStatus to go back to “idle”. Then using camera.listFiles to get the list of images captured by my brackets.
Is there a better way to use the auto bracket feature?

1 Like

I ran a test with autoBracket and it works the same as your code with my setup, SC2, firmware 1.31.

From my tests, I believe that the /osc/command/status works differently on the SC2 compared to the Z1 and the V when used with camera.startCapture. I believe that for the SC2, you need to use state with camera.startCapture.

set autobracket

import 'package:http/http.dart' as http;
import 'package:apitest/pretty_print.dart';
import 'dart:async';
import 'dart:convert';

Future<http.Response> autoBracket() async {
  var url = 'http://192.168.1.1/osc/commands/execute';

  Map data = {
    'name': 'camera.setOptions',
    'parameters': {
      'options': {
        "_autoBracket": {
          "_bracketNumber": 3,
          "_bracketParameters": [
            {"shutterSpeed": 0.004, "iso": 400, "_colorTemperature": 5100},
            {"shutterSpeed": 0.004, "iso": 320, "_colorTemperature": 5100},
            {"shutterSpeed": 0.004, "iso": 2500, "_colorTemperature": 5000}
          ]
        }
      }
    }
  };

  //encode Map to JSON
  var body = jsonEncode(data);

  var response = await http.post(url,
      headers: {"Content-Type": "application/json;charset=utf-8"}, body: body);
  print("${response.statusCode}");
  prettyPrint("${response.body}");
  return response;
}

start capture

import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:apitest/pretty_print.dart';


Future<http.Response> startCapture () async {
  var url ='http://192.168.1.1/osc/commands/execute';

  Map data = {
    'name': 'camera.startCapture',
    'parameters': {
      "_mode": "bracket"
    }
  };
  //encode Map to JSON
  var body = jsonEncode(data);

  var response = await http.post(url,
      headers: {"Content-Type": "application/json;charset=utf-8"},
      body: body
  );
  print("The HTTP response code is: ${response.statusCode}");
  print("The HTTP response from camera.startCapture is: ");
  prettyPrint("${response.body}");
  return response;
}

response from startCapture

The HTTP response code is: 200
The HTTP response from camera.startCapture is:

{
  "name": "camera.startCapture",
  "id": "2079",
  "progress": {
    "completion": 0.0
  },
  "state": "inProgress"
}

Can you provide more information on if this is a problem in your application? You seem to have the correct process.

I’m assuming you have a loop that is checking state, similar to the example below for takePicture.

If there is no problem with your solution, I’m going to add it to the SC2 community documentation below and provide the example for startCapture

Important Note about _captureStatus and Downloading Images

The SC2 appears to take quite a bit longer to be ready for the next picture shoot. The V/Z1 is faster in my experience. When you write your own program you should check _captureStatus with state to make sure the _captureStatus is idle.

The flow of your program will be as follows:

<--- camera.takePicture

----> response

<--- POST /osc/state

----> response _captureStatus: shooting

<--- POST /osc/state

----> response _captureStatus: shooting

<--- POST /osc/state

----> response _captureStatus: shooting

<--- POST /osc/state

----> response _captureStatus: shooting

<--- POST /osc/state

----> response _captureStatus: idle

<--- GET URL *URL = _LatestFileUrl of the state received immediately before

I just realized that the public API documentation has an example on /osc/commands/status that does not appear to work with the SC2. I confirmed your test with my own test. I put the picture below in the community documentation and provided attribution to you. That’s a nice find that you made. I can only imagine the frustration that other people have having.

Since I can use /osc/state to get the capture status I guess that is a solution.
camera.takePicture is working perfectly with /osc/command/status the issue was only with camera.startCapture.

Also when using brackets, the state gives _captureStatus: "bracket shooting", _capturedPictures: 2, the capturedPictures will update its count.

something else that I found is the command to get the supported shutter speed doesn’t return good values but this one is a bit out of context

{
  "name":"camera.getOptions", 
  "parameters": {
    "optionNames" : ["shutterSpeedSupport"]
  }
}
1 Like

Thanks for all your testing and help you’re providing to other people. I’m going to do some tests based on your information and update the community document that I’m helping to maintain.

I’ll test the shutterspeed as well.

Have a nice day.

1 Like

Hello @Craig,

Thanks for all your support regarding theta api versioning and integrations examples.

I have been testing inProgress couple of days, my case as following:

Just send command
camera.takePicture

And keep checking status of camera, the result returns inProgress but always completion is 0, then after a while it returns done and everything working perfect.

So I was trying to implement fake progress while camera is processing, the thing is I have tested it many times, but the processing time between 5 seconds up to 15 seconds ( default option/settings is used ) using SC2.

I will share the example project soon on Github for better vision on what is happening.

Thanks.

1 Like

Please post the firmware version. You can get it from info. It will look like this:

> .\theta.exe info
{
  "manufacturer": "RICOH",
  "model": "RICOH THETA SC2",
  "firmwareVersion": "01.51",

Are you using POST /osc/commands/status to get the state of the camera?

typical non-HDR shot is 10 seconds.

process:

  1. takePicture → returns status id
  2. get state of camera from status
  3. if `!= ‘done’ then go back to 2

Example to check on camera status.

Future<String> isDone(String id) async {
  var url = 'http://192.168.1.1/osc/commands/status';
  var data = {'id': id};

  var payload = jsonEncode(data);

  var response = await http.post(url,
      headers: {'Content-Type': 'application/json;charset=utf-8'},
      body: payload);

  Map<String, dynamic> status = jsonDecode(response.body);
  String state = status['state'];

  return state;
}

example with simple loop.

  var takePictureResponse = await ThetaRun.takePicture();
  String id = takePictureResponse['id'];
  print('The status ID is $id');

  var keepGoing = true;
  var elapsedSeconds = 0;

  while (keepGoing) {
    var currentStatus = await isDone(id);
    // print(currentStatus);

    await Future.delayed(const Duration(seconds: 1));
    print('Elapsed time: $elapsedSeconds seconds. State: $currentStatus');
    elapsedSeconds++;
    if (currentStatus == 'done') {
      keepGoing = false;
    }
  }

Working snippet on GitHub

webapi/take_and_ready.dart at master · theta360developers/webapi · GitHub

Example of take picture and then display on mobile app when it is ready.

GitHub - codetricity/flutter_sc2_image_test: RICOH THETA SC2 Flutter Test - takePicture, check status, download image

If you use startCapture, you must use /osc/state. From my tests, you can use /osc/status with takePicture on the SC2.

Please post more information on your problem. @jcasman and I will try and solve it.

Also, if you want to use the same API testing tool, send @jcasman an email and he can send you a link to the current binaries we’re using on Windows, Mac, Linux.

1 Like

@msabah Sounds like you’re making good progress! I did some testing recently on which process is quicker: Using takePicture or autoBracket. Results are here:

It’s easy for you to test it yourself. Drop me a note if you’d like access to the binaries. What’s your development environment?

@jcasman you can also replicate the same test I did on the Z1 with the SC2.

It’s theoretically problem that the SC2 is responding differently. change the anme to theta_endurance_test.sh and change the comments at the top if the SC2 is successful

Update February 20, 2021 - SC2 Failed Script Test

The above 500 picture endurance test using /osc/status failed for me with the SC2. The camera locks up.

@jcasman, can you run the script above on the SC2 and help me test it? I tried to increase the delay to 2 seconds and the camera still locks up.

I’m going to try a longer delay first and then if the camera still locks up, I am going to use osc/state.

The SC2 camera only locks up when many shots are taken in rapid sequence.

This is the test. I ran it on a Raspberry Pi. You may have better results from WSL2 or a mobile phone. Keep trying different scenarios.

Update February 20, 2021 late morning - SC2 Wi-Fi Stability Issue

@jcasman when you publish the tests with takePicture, please start a new topic. This topic originally started with startCapture. To make the tests on takePicture with the SC2 easier to find, start a new topic called, ‘SC2 takePicture repeat shots and camera status’ or something similar.

I just tried another test with the robot on the SC2 and had to replace the camera with a THETA V. I was not able to establish a stable Wi-Fi connection for hundreds of sequential shots between the SC2 and the RPi4. This may be due to the Wi-Fi chipset and use of 2.4GHz. There may be Wi-Fi interface in my office. I’m not sure. I think we can get the SC2 to work reliably for long-term sequential use, but at the moment, it is showing unexpected behavior under stress tests. We should document the test equipment and script when the test is done.

Update February 21, 2021 - SC2 working with long delays between shots

I’m building out my test results at the link below.

I’m consistently getting the output like this:

waiting 5 seconds for the next shot
Test of taking picture and then checking to see if picture is ready for download
---
The status ID is 8844
Elapsed time: 0 seconds. State: inProgress
Elapsed time: 1 seconds. State: inProgress
Elapsed time: 2 seconds. State: inProgress
Elapsed time: 3 seconds. State: inProgress
Elapsed time: 4 seconds. State: inProgress
Elapsed time: 5 seconds. State: inProgress
Elapsed time: 6 seconds. State: inProgress
Elapsed time: 7 seconds. State: inProgress
Elapsed time: 8 seconds. State: done
picture ready for download at http://192.168.1.1/files/thetasc26c21a247d9055838792bad
c5/100RICOH/R0010714.JPG

With a non-HDR filter, the picture consistently takes 8 seconds to be ready for the next picture.

Thus, you can create a fake progress bar by using the elapsed time.

If I don’t insert a delay between shots, I can’t accurately check the inProgress as the camera locks up.

Test with 5 second delay after done is received

I’m redoing the test again with a 5 second delay, 200 shots. This is a delay of 5 seconds after I receive the status as done. This means that I am waiting a total of 13 seconds between shots, not including the download time. In this test, I am not downloading the image after each shot.

Result with 5 second delay: test failed

Test with 8 second delay after done is received

Redoing test with 8 second delay. This is 8 second after I receive the done status. Time between shots is at least 16 seconds.


More tests

@msabah It sounds like you are making good progress!

@codetricity and I are doing some more testing here. Can you confirm you are:

  • Not setting hdr
  • Using takePicture, not startCapture

We don’t know, but we think if pictures are taken in succession, there may be a problem.

Even if it says “done,” if you take another picture immediately, there might be a problem.

Try inserting a 3 second delay in between shots. We’re not 100% sure. But this is what we are currently testing. Just giving you this update right now.

We’re doing more testing. Here’s the current results:

Yes Craig, I’m using /osc/status with takePicture on the SC2 and working good.

Also my implementation is almost identical to your examples regarding checking if it’s done.

We changed our UI from progress to loading indicator, so I guess we are ok for now. Many thanks.

2 Likes