Python Forum
Reading coordinates in tiff images using PyQt
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading coordinates in tiff images using PyQt
#11
I tried a 400 MB and an 8 MB .tiff, none of which worked.
Thanks
Reply
#12
What is your OS and opencv-python Version? I have 4.4

Output:
pip3 show opencv-python Name: opencv-python Version: 4.4.0.46 Summary: Wrapper package for OpenCV python bindings. Home-page: https://github.com/skvark/opencv-python Author: None Author-email: None License: MIT Location: /home/brian/.local/lib/python3.8/site-packages Requires: numpy
hobbyist likes this post
Reply
#13
Hello, it shows me this:

Error:
UbuntuUser@ubuntu:~/Desktop/PyQT$ pip3 show opencv-python WARNING: Package(s) not found: opencv-python
I re-install OpenCV with these commands:

sudo apt update
sudo apt install libopencv-dev python3-opencv
and I still get the message above...What is wrong?

update: I ran this command:
pip install opencv-python
and it seems opencv to be installed.
When I try to run the python_code.py file, I get this error:

Error:
QObject::moveToThread: Current thread (0x21735e0) is not the object's thread (0x28819c0). Cannot move to target thread (0x21735e0) qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/mojito/.local/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl. Aborted (core dumped)
I use a small .tiff (about 8 MBytes)

I installed again opencv:

pip install opencv-python-headless
the above error has gone, but when I continue to see this error:

cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-h2062vqd/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
I use Ubuntu 20.04.1 and opencv version: Version: 4.4.0.46
Reply
#14
whats the output of

pip2 show pip

and

pip3 show pip

maybe you should use pip3 install ...
hobbyist likes this post
Reply
#15
UbuntuUser@ubuntu:~/Desktop/PyQT$ pip2 show pip

Command 'pip2' not found, did you mean:

  command 'pipx' from deb pipx (0.12.3.1-2ubuntu1)
  command 'nip2' from deb nip2 (8.7.0-1)
  command 'pip3' from deb python3-pip (20.0.2-5ubuntu1.1)

Try: sudo apt install <deb name>

UbuntuUser@ubuntu:~/Desktop/PyQT$ pip3 show pip
Name: pip
Version: 20.3.1
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python3.8/dist-packages
Requires: 
Required-by: 
Reply
#16
I made a test using lalala.png (that does not exists) and getting the same error message

Output:
cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-h2062vqd/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
It is a file not found error (src.empty())
hobbyist likes this post
Reply
#17
I am trying to combine the above code with rasterio https://rasterio.readthedocs.io/en/latest/
in order to open the tiff files. I get these errors:

Error:
MainThread INFO 2020-12-20 04:05:11,775 TaurusRootLogger: Using PyQt5 (v5.15.2 with Qt 5.15.2 and Python 3.8.5) Traceback (most recent call last): File "OrthoView_with_rasterio.py", line 678, in <module> window = OrthoView() File "OrthoView_with_rasterio.py", line 530, in __init__ self.updateFrame() File "OrthoView_with_rasterio.py", line 570, in updateFrame self.getFrame() File "OrthoView_with_rasterio.py", line 540, in getFrame self.img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) TypeError: Expected Ptr<cv::UMat> for argument 'src'
Any ideas?
Reply
#18
This is the change, that I have done. Any ideas what is wrong?

    def getFrame(self):                                                       # <---- line 533
        if isTest:
            fp = r'/home/UbuntuUser/Desktop/UAV_test.tif'                     # <----- here                 
            frame = rasterio.open(fp)                                         # <----- here
            # OpenCV uses BGR as its default colour order for images
            self.img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)                 # <----- here
#            import pickle
#            with open(r"_images/sample-holder-test2.pickle", 'rb') as f:
#                try:
#                    packed = pickle.load(f, encoding='latin1')
#                except TypeError:
#                    packed = pickle.load(f)
#            unpacked = np.empty(list(packed.shape)+[3], dtype=np.uint8)
#            unpacked[:, :, 2] = (packed >> 16) & 0xff
#            unpacked[:, :, 1] = (packed >> 8) & 0xff
#            unpacked[:, :, 0] = packed & 0xff
#            self.img = unpacked

        else:
            frame = self.camera.read_attribute('Image').value

            # for monochrome frames:
#            self.img = cv2.normalize(
#                src=frame, dst=None, alpha=0, beta=255,
#                norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8UC1)
#            self.img = cv2.cvtColor(self.img, cv2.COLOR_GRAY2BGR)

            # for color frames:
            unpacked = np.empty(list(frame.shape)+[3], dtype=np.uint8)
            unpacked[:, :, 2] = (frame >> 16) & 0xff
            unpacked[:, :, 1] = (frame >> 8) & 0xff
            unpacked[:, :, 0] = frame & 0xff
            self.img = unpacked
Reply
#19
Ok, it works partially, when using small .tiff files around 10 MB, but with 400-500 MB, I have this error:

Error:
cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-h2062vqd/opencv/modules/core/src/alloc.cpp:73: error: (-4:Insufficient memory) Failed to allocate 24586133472 bytes in function 'OutOfMemoryError'
After searching on google there are people that suggest to downsize the image, but in that situation I lose a lot of information. Is here any other way to handle such large images? The VM has 16 GB (real) RAM which is more than enough to handle the 500MB image...am I loosing something here? How can a 500MB causes the need of 24 GB RAM?!!!
Reply
#20
Your image is not 400-500 MBytes, the compressed image is. What is the actual size of your images (pixel count)?

What is the program doing when it runs out of memory? I looked at some of the code in this post a while back and I saw it loaded an image and then converted to greyscale. I think you would save a lot of memory by converting the file as it loads.
hobbyist likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PySide / PyQt] Offset two images with keyboard increments carecavoador 1 1,006 Sep-09-2023, 12:53 PM
Last Post: deanhystad
  [Tkinter] Plotting Raster Data / TIFF files on tkinter canvas RRSCNGP 0 2,588 Aug-28-2019, 04:44 AM
Last Post: RRSCNGP

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020