by256 / imagedataextractor

ImageDataExtractor 2.0 - a Python library for electron microscopy image quantification.
https://imagedataextractor.org
MIT License
12 stars 2 forks source link

OpenCV error #10

Closed dyhl0 closed 2 years ago

dyhl0 commented 2 years ago

code issue Traceback (most recent call last)

in 1 im_path = './example-image.png' 2 device = 'cpu' ----> 3 data = ide.extract(im_path, 4 seg_bayesian=True, # Bayesian mode 5 seg_tu=0.0125, # uncertainty threshold beyond which to filter FPs D:\hebida\lib\site-packages\imagedataextractor-2.0.4-py3.8.egg\imagedataextractor\extract.py in extract(input_path, seg_bayesian, seg_n_samples, seg_tu, seg_device) 61 images = [image] 62 for i, im in enumerate(images): ---> 63 em_data = _extract_image(im, seg_bayesian, seg_n_samples, seg_tu, seg_device) 64 if len(images) == 1: 65 em_data.fn = fn D:\hebida\lib\site-packages\imagedataextractor-2.0.4-py3.8.egg\imagedataextractor\extract.py in _extract_image(image, seg_bayesian, seg_n_samples, seg_tu, seg_device) 130 sb_detector = ScalebarDetector() 131 segmenter = ParticleSegmenter(bayesian=seg_bayesian, n_samples=seg_n_samples, tu=seg_tu, device=seg_device) --> 132 shape_detector = ShapeDetector() 133 134 # initialise EM data object D:\hebida\lib\site-packages\imagedataextractor-2.0.4-py3.8.egg\imagedataextractor\analysis\shapedetect.py in __init__(self) 17 self.shapes_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'shapes/') 18 self.shapes_dict = None # key - name, value - image ---> 19 self.populate_shape_dict() 20 21 def match_shapes(self, mask): D:\hebida\lib\site-packages\imagedataextractor-2.0.4-py3.8.egg\imagedataextractor\analysis\shapedetect.py in populate_shape_dict(self) 46 for shape_name in self.shape_names: 47 shape_image = cv2.imread(os.path.join(self.shapes_dir, '{}.png'.format(shape_name))) ---> 48 shape_image = cv2.cvtColor(shape_image, cv2.COLOR_BGR2GRAY) 49 shape_images.append(shape_image) 50 self.shapes_dict = dict(zip(self.shape_names, shape_images)) error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
dyhl0 commented 2 years ago

Hi OP, I was using the exact same image in the example and I am not sure what is going on. I hope that you can help me out with this. Thank you in advance

by256 commented 2 years ago

Hi,

Can you check that you're using the correct version of opencv:

opencv-python==4.2.0.32.

If not, install the correct version and try again. If this doesn't work, let me know and we can try to figure it out.

Batuhan

dyhl0 commented 2 years ago

ide issue Hi OP, this is the opencv in my conda list which is the same one that you have specified, yet the problem still persists.

by256 commented 2 years ago

That's strange because it works on my end.

One ugly solution is to go to the path where imagedataextractor is installed:

D:\hebida\lib\site-packages\imagedataextractor-2.0.4-py3.8.egg\imagedataextractor\

and edit the extract.py file. Comment out or delete any lines involving shape detection as this seems to be what's causing the problem: line 132 and lines 198 to 211.

I can look into this issue further when I have more time, but let me know if this fixes your issue for now.

dyhl0 commented 2 years ago

Hi OP, I have redownloaded everything and found out that the problem was in tesseract, I have mistakenly downloaded the newest version instead of 4.0. Everything was rectified after the correct version has been downloaded. I am really sorry that I have inconvenienced you and thank you for answering my queries.

by256 commented 2 years ago

Great. Glad to hear you solved it.