Home>

I'm running Python3 with a camera sensor connected to a rasp pie.
There is a part in the program that I want to execute every time the "frame number" included in the data sent from the camera increases by a certain number.

Loop the whole with while, and every time "frame_number" included in the return value from the camera increases by a certain number (10,000 in this case), create another variable fn to execute the contents of if and branch it I have included it, but I can't do what I wanted.

You can see that f_n = 0 is meaningless when frame_number goes over time from the start, but I can't figure out how to do it.

frame_number does not increase by the same value every time, but it seems to be slightly different (?) depending on the time taken by the last processing etc.

Applicable source code
while 1:
 fn = fn + frame_number
 if fn/10000>1:
  (Omitted) #Execute this process
  fn = 0
Supplemental information (FW/tool version etc.)

Python 3.5.3

  • Answer # 1

    fn = 0
    while 1:
     if (frame_number-fn)/10000>1:
      (Omitted) #Execute this process
      fn = frame_number // 10000 * 10000

    The above should be executed once when frame_number is 10,000, once when frame_number is 20,000, and so on.

  • Answer # 2

      

    fn = fn + frame_number

    For example, if frame_number is 10 and if the while loop is repeated 10 times, let's consider what value fn will be, and what value should it be?

Related articles