chpoit / utsushis-charm

Easily import all of your Monster Hunter Rise charms to your armor set searcher of choice
MIT License
48 stars 5 forks source link

TypeError: expected str, bytes or os.PathLike object, not NoneType #13

Closed chalkos closed 3 years ago

chalkos commented 3 years ago

I found this while trying to run on a mac

▶ python3 main.py
Traceback (most recent call last):
  File "/Users/Chalkos/projects/utsushis-charm/main.py", line 1, in <module>
    from src.__main__ import main
  File "/Users/Chalkos/projects/utsushis-charm/src/__main__.py", line 3, in <module>
    from .frame_extraction import extract_unique_frames
  File "/Users/Chalkos/projects/utsushis-charm/src/frame_extraction.py", line 3, in <module>
    from .utils import apply_pre_crop_mask, get_frame_change_observation_section, get_resource_path
  File "/Users/Chalkos/projects/utsushis-charm/src/utils.py", line 7, in <module>
    tess = Tesseract()
  File "/Users/Chalkos/projects/utsushis-charm/src/manual_tesseract_bindings.py", line 113, in __init__
    self.setup_lib(lib_path)
  File "/Users/Chalkos/projects/utsushis-charm/src/manual_tesseract_bindings.py", line 71, in setup_lib
    lib_path = find_tesseract()
  File "/Users/Chalkos/projects/utsushis-charm/src/manual_tesseract_bindings.py", line 24, in find_tesseract
    os.path.join(os.getenv("ProgramW6432"),
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/posixpath.py", line 76, in join
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType

It seems to be because I dont have ProgramW6432 defined. I'll submit a PR later if I manage to fix it (if, because I have never touched python before) and other info needed to run this on a mac to the readme

chpoit commented 3 years ago

I already know where it crashed. I am suprised it dies if an environment variable isn't present. Give me 10 minutes, I'll push a branch where it wont crash.

chpoit commented 3 years ago

I pushed it under tesseract-env-fix.

If you want to add the env names for the "Program Files" equivalent on MacOS, feel free, just check the file src/manual_tesseract_bindings.py lines 38-43, the "Darwin" section.

chalkos commented 3 years ago

I'll try that branch. I don't think there's a "Program Files" equivalent. What you need to use is just made available in the path

chalkos commented 3 years ago

It worked for a dry run. I also needed another environment variable for tesseract to load. I'll add some videos later to see if it works fine from start to end

chalkos commented 3 years ago

The old video files seem ok. I'm using tesseract 4.1.1 so I wanted to test that

Total input files to scan: 6
2021051218071900_s.mp4,  Total Estimated charms/frames found: 102: 100%|██████████████| 891/891 [00:19<00:00, 45.37it/s]
2021051218075600_s.mp4,  Total Estimated charms/frames found: 205: 100%|██████████████| 899/899 [00:19<00:00, 45.25it/s]
2021051218085500_s.mp4,  Total Estimated charms/frames found: 308: 100%|██████████████| 884/884 [00:19<00:00, 46.47it/s]
2021051218082500_s.mp4,  Total Estimated charms/frames found: 411: 100%|██████████████| 879/879 [00:19<00:00, 46.21it/s]
2021051218091000_s.mp4,  Total Estimated charms/frames found: 450: 100%|██████████████| 464/464 [00:10<00:00, 45.29it/s]
2021051218062900_s.mp4,  Total Estimated charms/frames found: 552: 100%|██████████████| 888/888 [00:19<00:00, 45.77it/s]
Detecting non-sequential duplicate frames: 100%|██████████████████████████████████████| 552/552 [00:10<00:00, 51.17it/s]
Reduced frames from 552 to 539
Parsing skill and slots: 100%|████████████████████████████████████████████████████████| 539/539 [00:19<00:00, 27.58it/s]
Validating and fixing charms: 100%|████████████████████████████████████████████████| 539/539 [00:00<00:00, 64196.10it/s]
Pre-duplicate 539
Post-duplicate: 533
Duplicate charms can be found in charm.duplicates.txt
Saved 533 charms
Encoding charms
Charms encoded under "charms.encoded.txt". Use the contents of that file on the MHR Wiki armor set builder
Press Enter to Exit...

I then I tried with the new videos and (I forgot to remove the old frames so there were a lot of duplicates, so after i removed them) it ran ok as well..

Total input files to scan: 8
2021051603384300_s.mp4,  Total Estimated charms/frames found: 107: 100%|██████████████| 895/895 [00:19<00:00, 44.88it/s]
2021051603365700_s.mp4,  Total Estimated charms/frames found: 211: 100%|██████████████| 892/892 [00:19<00:00, 45.44it/s]
2021051603411300_s.mp4,  Total Estimated charms/frames found: 253: 100%|██████████████| 885/885 [00:19<00:00, 46.33it/s]
2021051603395300_s.mp4,  Total Estimated charms/frames found: 357: 100%|██████████████| 896/896 [00:19<00:00, 46.19it/s]
2021051603361900_s.mp4,  Total Estimated charms/frames found: 459: 100%|██████████████| 885/885 [00:19<00:00, 45.93it/s]
2021051603381000_s.mp4,  Total Estimated charms/frames found: 564: 100%|██████████████| 887/887 [00:19<00:00, 44.75it/s]
2021051603373200_s.mp4,  Total Estimated charms/frames found: 669: 100%|██████████████| 895/895 [00:20<00:00, 44.24it/s]
2021051603391800_s.mp4,  Total Estimated charms/frames found: 773: 100%|██████████████| 891/891 [00:20<00:00, 44.22it/s]
Detecting non-sequential duplicate frames: 100%|██████████████████████████████████████| 773/773 [00:19<00:00, 38.73it/s]
Reduced frames from 773 to 744
Parsing skill and slots: 100%|████████████████████████████████████████████████████████| 745/745 [00:27<00:00, 27.26it/s]
Validating and fixing charms: 100%|███████████████████████████████████████████████| 744/744 [00:00<00:00, 114802.52it/s]
Pre-duplicate 744
Post-duplicate: 728
Duplicate charms can be found in charm.duplicates.txt
Saved 728 charms
Encoding charms
Charms encoded under "charms.encoded.txt". Use the contents of that file on the MHR Wiki armor set builder
Press Enter to Exit...

I'll add the PR later, but there's not much to add... just 2 lines on the readme but no easy way to run this on a mac. I don't think it would be as easy for a non-dev to run this on a mac similarly to how you do on windows, because to install tesseract you need a bunch of developer tools and a few GB of downloads which seems like too much of a hassle.. But I'll try to find an easy way to package & run it on a mac and let you know my findings

Anyway the fix worked so feel free to close this ticket

chpoit commented 3 years ago

Yeah, I figure it would be the same on linux. I might try just distributing the required DLLs or libraries if the licenses for tesseract's dependencies allow that. It would make it so you don't even need to install it on any machine.

chalkos commented 3 years ago

I found this https://github.com/sirfz/tesserocr If it does the same as the installed tesseract does now, maybe it could be used. From what I understand all python libraries get packaged in the exe (or even MacOS executable file later on) so it wouldn't need tesseract installed at all. Plus there's some mention of it being possible to use it with python's threading module, which could maybe enable the multithreading thing you were working on.