float” object cannot be interpreted as an integer while reading the frame












0












$begingroup$


I am trying to read the frames using imageio API. I have a reader as an object which I have received using imageio.get_reader(video_path,"ffmpeg"). I have the following frame reader function



def read_frames(reader, frame_q, use_webcam):
if use_webcam:
time.sleep(15)
frame_cnt = 0
while True:
#if frame_cnt % 5 == 0:
# ret, frame = reader.read()
# cur_img = frame[:,:,::-1]
# frame_q.put(cur_img)
#else:
# ret, frame = reader.read()
ret, frame = reader.read()
cur_img = frame[:,:,::-1] # bgr to rgb from opencv reader
frame_q.put(cur_img)
if frame_q.qsize() > 100:
time.sleep(1)
else:
time.sleep(DELAY/1000.)

#print(cur_img.shape)

else:
#for cur_img in reader: # this is imageio reader, it uses rgb
nframes = reader.get_length() **#getting error here**
# if nframes == float('inf') or nframes ==float('-inf'):
# return float("nan")
# return int(nframes)

for ii in range(nframes):
while frame_q.qsize() > 500: # so that we dont use huge amounts of memory
time.sleep(1)
cur_img = reader.get_next_data()
frame_q.put(cur_img)
#shape = cur_img.shape
#noisy_img = np.uint8(cur_img.astype(np.float) + np.random.randn(*shape) * 20)
#frame_q.put(noisy_img)
if ii % 100 == 0:
print("%i / %i frames in queue" % (ii, nframes))
print("All %i frames in queue" % (nframes))


Traceback :



Traceback (most recent call last):
File "/home/prashantb/anaconda3/envs/demo/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/home/prashantb/anaconda3/envs/demo/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "multiprocess_detect_actions.py", line 67, in read_frames
for ii in range(nframes):
TypeError: 'float' object cannot be interpreted as an integer


I tried to use float('inf')as commented in the code but it is not useful in this case. I also tried to convert a float value to integer but it showing the same error. I would appreciate your advice on this. thank you.










share|improve this question







New contributor




Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$

















    0












    $begingroup$


    I am trying to read the frames using imageio API. I have a reader as an object which I have received using imageio.get_reader(video_path,"ffmpeg"). I have the following frame reader function



    def read_frames(reader, frame_q, use_webcam):
    if use_webcam:
    time.sleep(15)
    frame_cnt = 0
    while True:
    #if frame_cnt % 5 == 0:
    # ret, frame = reader.read()
    # cur_img = frame[:,:,::-1]
    # frame_q.put(cur_img)
    #else:
    # ret, frame = reader.read()
    ret, frame = reader.read()
    cur_img = frame[:,:,::-1] # bgr to rgb from opencv reader
    frame_q.put(cur_img)
    if frame_q.qsize() > 100:
    time.sleep(1)
    else:
    time.sleep(DELAY/1000.)

    #print(cur_img.shape)

    else:
    #for cur_img in reader: # this is imageio reader, it uses rgb
    nframes = reader.get_length() **#getting error here**
    # if nframes == float('inf') or nframes ==float('-inf'):
    # return float("nan")
    # return int(nframes)

    for ii in range(nframes):
    while frame_q.qsize() > 500: # so that we dont use huge amounts of memory
    time.sleep(1)
    cur_img = reader.get_next_data()
    frame_q.put(cur_img)
    #shape = cur_img.shape
    #noisy_img = np.uint8(cur_img.astype(np.float) + np.random.randn(*shape) * 20)
    #frame_q.put(noisy_img)
    if ii % 100 == 0:
    print("%i / %i frames in queue" % (ii, nframes))
    print("All %i frames in queue" % (nframes))


    Traceback :



    Traceback (most recent call last):
    File "/home/prashantb/anaconda3/envs/demo/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
    File "/home/prashantb/anaconda3/envs/demo/lib/python3.6/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
    File "multiprocess_detect_actions.py", line 67, in read_frames
    for ii in range(nframes):
    TypeError: 'float' object cannot be interpreted as an integer


    I tried to use float('inf')as commented in the code but it is not useful in this case. I also tried to convert a float value to integer but it showing the same error. I would appreciate your advice on this. thank you.










    share|improve this question







    New contributor




    Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      0












      0








      0





      $begingroup$


      I am trying to read the frames using imageio API. I have a reader as an object which I have received using imageio.get_reader(video_path,"ffmpeg"). I have the following frame reader function



      def read_frames(reader, frame_q, use_webcam):
      if use_webcam:
      time.sleep(15)
      frame_cnt = 0
      while True:
      #if frame_cnt % 5 == 0:
      # ret, frame = reader.read()
      # cur_img = frame[:,:,::-1]
      # frame_q.put(cur_img)
      #else:
      # ret, frame = reader.read()
      ret, frame = reader.read()
      cur_img = frame[:,:,::-1] # bgr to rgb from opencv reader
      frame_q.put(cur_img)
      if frame_q.qsize() > 100:
      time.sleep(1)
      else:
      time.sleep(DELAY/1000.)

      #print(cur_img.shape)

      else:
      #for cur_img in reader: # this is imageio reader, it uses rgb
      nframes = reader.get_length() **#getting error here**
      # if nframes == float('inf') or nframes ==float('-inf'):
      # return float("nan")
      # return int(nframes)

      for ii in range(nframes):
      while frame_q.qsize() > 500: # so that we dont use huge amounts of memory
      time.sleep(1)
      cur_img = reader.get_next_data()
      frame_q.put(cur_img)
      #shape = cur_img.shape
      #noisy_img = np.uint8(cur_img.astype(np.float) + np.random.randn(*shape) * 20)
      #frame_q.put(noisy_img)
      if ii % 100 == 0:
      print("%i / %i frames in queue" % (ii, nframes))
      print("All %i frames in queue" % (nframes))


      Traceback :



      Traceback (most recent call last):
      File "/home/prashantb/anaconda3/envs/demo/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
      self.run()
      File "/home/prashantb/anaconda3/envs/demo/lib/python3.6/multiprocessing/process.py", line 93, in run
      self._target(*self._args, **self._kwargs)
      File "multiprocess_detect_actions.py", line 67, in read_frames
      for ii in range(nframes):
      TypeError: 'float' object cannot be interpreted as an integer


      I tried to use float('inf')as commented in the code but it is not useful in this case. I also tried to convert a float value to integer but it showing the same error. I would appreciate your advice on this. thank you.










      share|improve this question







      New contributor




      Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I am trying to read the frames using imageio API. I have a reader as an object which I have received using imageio.get_reader(video_path,"ffmpeg"). I have the following frame reader function



      def read_frames(reader, frame_q, use_webcam):
      if use_webcam:
      time.sleep(15)
      frame_cnt = 0
      while True:
      #if frame_cnt % 5 == 0:
      # ret, frame = reader.read()
      # cur_img = frame[:,:,::-1]
      # frame_q.put(cur_img)
      #else:
      # ret, frame = reader.read()
      ret, frame = reader.read()
      cur_img = frame[:,:,::-1] # bgr to rgb from opencv reader
      frame_q.put(cur_img)
      if frame_q.qsize() > 100:
      time.sleep(1)
      else:
      time.sleep(DELAY/1000.)

      #print(cur_img.shape)

      else:
      #for cur_img in reader: # this is imageio reader, it uses rgb
      nframes = reader.get_length() **#getting error here**
      # if nframes == float('inf') or nframes ==float('-inf'):
      # return float("nan")
      # return int(nframes)

      for ii in range(nframes):
      while frame_q.qsize() > 500: # so that we dont use huge amounts of memory
      time.sleep(1)
      cur_img = reader.get_next_data()
      frame_q.put(cur_img)
      #shape = cur_img.shape
      #noisy_img = np.uint8(cur_img.astype(np.float) + np.random.randn(*shape) * 20)
      #frame_q.put(noisy_img)
      if ii % 100 == 0:
      print("%i / %i frames in queue" % (ii, nframes))
      print("All %i frames in queue" % (nframes))


      Traceback :



      Traceback (most recent call last):
      File "/home/prashantb/anaconda3/envs/demo/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
      self.run()
      File "/home/prashantb/anaconda3/envs/demo/lib/python3.6/multiprocessing/process.py", line 93, in run
      self._target(*self._args, **self._kwargs)
      File "multiprocess_detect_actions.py", line 67, in read_frames
      for ii in range(nframes):
      TypeError: 'float' object cannot be interpreted as an integer


      I tried to use float('inf')as commented in the code but it is not useful in this case. I also tried to convert a float value to integer but it showing the same error. I would appreciate your advice on this. thank you.







      python image






      share|improve this question







      New contributor




      Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 11 mins ago









      SamSam

      1




      1




      New contributor




      Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Sam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Sam is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f213940%2ffloat-object-cannot-be-interpreted-as-an-integer-while-reading-the-frame%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Sam is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Sam is a new contributor. Be nice, and check out our Code of Conduct.













          Sam is a new contributor. Be nice, and check out our Code of Conduct.












          Sam is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f213940%2ffloat-object-cannot-be-interpreted-as-an-integer-while-reading-the-frame%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin