I've newly installed imgstore and have unpredictable failures of get_image. Any ideas on how to fix it? I'm guessing there is an issue with my installation. I followed the instructions (opencv < 4.9) but additionally needed to use numpy < 2 (and tried using python 3.10 before figuring out the numpy issue). I initially thought that the post-install tests of imgstore looked fine (except for failed write tests, but I only need to read) but then noticed two other failed tests which might be relevant, entered as a comment below.
The problem: get_image works fine in a loop where I sequentially process each frame in a for loop, but fails for some frame numbers when called later for the frames of interest. Example below from debugging attempts, for a frame where it fails sometimes and works sometimes.
The code I'm using worked fine on my old PC, but that was so old that it was python 2. So I suspect it's an issue with my install, but can't figure out what needs to be changed.
Example of the error (from debugging in ipython; fn is the frame_number output of get_frame_metadata():
In [247]: store.get_image(fn[266])
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[247], line 1
----> 1 store.get_image(fn[266])
File ~/miniconda3/envs/imgstore_py_3_10/lib/python3.10/site-packages/imgstore/stores.py:716, in _ImgStore.get_image(self, frame_number, exact_only, frame_index)
714 return self._get_image_by_frame_index(frame_index)
715 else:
--> 716 return self._get_image_by_frame_number(frame_number, exact_only=exact_only)
File ~/miniconda3/envs/imgstore_py_3_10/lib/python3.10/site-packages/imgstore/stores.py:696, in _ImgStore._get_image_by_frame_number(self, frame_number, exact_only)
693 if chunk_n == -1:
694 raise ValueError('frame #%s not found in any chunk' % frame_number)
--> 696 return self._get_image(chunk_n, frame_idx)
File ~/miniconda3/envs/imgstore_py_3_10/lib/python3.10/site-packages/imgstore/stores.py:648, in _ImgStore._get_image(self, chunk_n, frame_idx)
645 self._load_chunk(chunk_n)
647 # ensure the read works before setting frame_number
--> 648 _img, (_frame_number, _frame_timestamp) = self._load_image(frame_idx)
649 img = self._decode_image(_img)
650 self._chunk_current_frame_idx = frame_idx
File ~/miniconda3/envs/imgstore_py_3_10/lib/python3.10/site-packages/imgstore/stores.py:1140, in VideoImgStore._load_image(self, idx)
1137 _, _img = self._cap.read()
1138 if self._color:
1139 # almost certainly no-op as opencv usually returns color frames....
-> 1140 img = ensure_color(_img)
1141 else:
1142 img = ensure_grayscale(_img)
File ~/miniconda3/envs/imgstore_py_3_10/lib/python3.10/site-packages/imgstore/util.py:48, in ensure_color(img, ensure_copy)
47 def ensure_color(img, ensure_copy=False):
---> 48 return _cvt_color(img, cv2.COLOR_GRAY2BGR, ensure_copy=ensure_copy)
File ~/miniconda3/envs/imgstore_py_3_10/lib/python3.10/site-packages/imgstore/util.py:27, in _cvt_color(img, code, ensure_copy)
25 def _cvt_color(img, code, ensure_copy=True):
26 # protect against empty last dimensions
---> 27 _is_color = (img.shape[-1] == 3) & (img.ndim == 3)
29 if code == cv2.COLOR_GRAY2BGR:
30 if _is_color:
AttributeError: 'NoneType' object has no attribute 'shape'
And then it works fine for that frame if I grab the one before it first.
In [248]: store.get_image(fn[265])
Out[248]:
(array([[[ 3, 3, 3],
[ 3, 3, 3],
[ 3, 3, 3],
...,
[27, 34, 20],
[28, 35, 21],
[28, 35, 21]],
[[ 3, 3, 3],
[ 3, 3, 3],
[ 3, 3, 3],
...,
[27, 34, 20],
[28, 35, 21],
[28, 35, 21]],
[[ 3, 3, 3],
[ 3, 3, 3],
[ 3, 3, 3],
...,
[27, 34, 20],
[28, 35, 21],
[28, 35, 21]],
...,
[[ 6, 5, 0],
[ 6, 5, 0],
[ 6, 5, 0],
...,
[ 1, 5, 0],
[ 1, 5, 0],
[ 1, 5, 0]],
[[ 6, 5, 0],
[ 6, 5, 0],
[ 6, 5, 0],
...,
[ 1, 5, 0],
[ 1, 5, 0],
[ 1, 5, 0]],
[[ 6, 5, 0],
[ 6, 5, 0],
[ 6, 5, 0],
...,
[ 1, 5, 0],
[ 1, 5, 0],
[ 1, 5, 0]]], dtype=uint8),
(266, 1749119598.7516336))
In [249]: store.get_image(fn[266])
Out[249]:
(array([[[ 3, 3, 3],
[ 3, 3, 3],
[ 3, 3, 3],
...,
[25, 34, 20],
[26, 35, 21],
[26, 35, 21]],
[[ 3, 3, 3],
[ 3, 3, 3],
[ 3, 3, 3],
...,
[25, 34, 20],
[26, 35, 21],
[26, 35, 21]],
[[ 3, 3, 3],
[ 3, 3, 3],
[ 3, 3, 3],
...,
[25, 34, 20],
[26, 35, 21],
[26, 35, 21]],
...,
[[ 8, 10, 3],
[ 6, 8, 1],
[ 4, 6, 0],
...,
[ 1, 5, 0],
[ 1, 5, 0],
[ 1, 5, 0]],
[[ 8, 10, 3],
[ 6, 8, 1],
[ 4, 6, 0],
...,
[ 1, 5, 0],
[ 1, 5, 0],
[ 1, 5, 0]],
[[ 8, 10, 3],
[ 6, 8, 1],
[ 4, 6, 0],
...,
[ 1, 5, 0],
[ 1, 5, 0],
[ 1, 5, 0]]], dtype=uint8),
(267, 1749119598.768245))
I've newly installed imgstore and have unpredictable failures of get_image. Any ideas on how to fix it? I'm guessing there is an issue with my installation. I followed the instructions (opencv < 4.9) but additionally needed to use numpy < 2 (and tried using python 3.10 before figuring out the numpy issue). I initially thought that the post-install tests of imgstore looked fine (except for failed write tests, but I only need to read) but then noticed two other failed tests which might be relevant, entered as a comment below.
The problem: get_image works fine in a loop where I sequentially process each frame in a for loop, but fails for some frame numbers when called later for the frames of interest. Example below from debugging attempts, for a frame where it fails sometimes and works sometimes.
The code I'm using worked fine on my old PC, but that was so old that it was python 2. So I suspect it's an issue with my install, but can't figure out what needs to be changed.
My installed packages:
Example of the error (from debugging in ipython; fn is the frame_number output of get_frame_metadata():
And then it works fine for that frame if I grab the one before it first.
Very grateful for any suggestions!
Clio