OpenCV: "Incorrect size of input array" error pop-up even with UI disabled
EDIT: I wasn't sure this has anything to do with the library, but this exact error also happens in Twack32 so I at least know it's not any modules in my app
I'm working with the library in Python, making an app that should handle all errors with no pop-ups, and I'm trying to handle an error where a user pulls a card out in the middle of a scan with a Plustek MobileOffice D620. Only trying to handle this error because I see many people end up doing this.
I initialize twain with dtwain_dll.DTWAIN_SysInitializeNoBlocking() and set the following
self.twain_source = self.dtwain_dll.DTWAIN_SelectSourceByName(self.source_name)
self.dtwain_dll.DTWAIN_EnableDuplex(self.twain_source, True)
self.dtwain_dll.DTWAIN_EnableFeeder(self.twain_source, True)
self.dtwain_dll.DTWAIN_EnableAutoFeed(self.twain_source, False)
self.dtwain_dll.DTWAIN_EnableMsgNotify(False)
Then later I acquire a scan with this:
result = dtwain_dll.DTWAIN_AcquireFile(source, "TEST.BMP", dtwain.DTWAIN_BMP, dtwain.DTWAIN_USELONGNAME, dtwain.DTWAIN_PT_DEFAULT, 1, False, True, 0)
with bShowUI set to False to prevent any pop-ups. When I run the scan, and pull the card out while it scans. It shows this popup and all options crash my app (crashing is out of DTwain's scope most likely).
In a basic script, it returns error -1023 DTWAIN_ERR_UI_ERROR "Error in displaying Source User Interface" after pressing Ignore or Abort even though I'm not trying to show any interface whatsoever. Is there something I'm missing to be able to handle this without any pop-ups?
And this was the minimal script I was doing to ensure no additional modules were causing issues: basically the same as the python example in the readme
from ctypes import *
from dtwain32 import dtwain
class TwainScanner:
def __init__(self):
self.dtwain_dll = windll.LoadLibrary("./dtwain32/dtwain32u.dll")
self.dtwain_dll.DTWAIN_SysInitializeNoBlocking()
self.twain_source = self.dtwain_dll.DTWAIN_SelectSourceByName("Plustek MobileOffice A6 Duplex BU")
self.dtwain_dll.DTWAIN_EnableDuplex(self.twain_source, True)
self.dtwain_dll.DTWAIN_EnableFeeder(self.twain_source, True)
self.dtwain_dll.DTWAIN_EnableAutoFeed(self.twain_source, False)
self.dtwain_dll.DTWAIN_EnableMsgNotify(False)
def get_scan(self, scan_timeout=12):
self.dtwain_dll.DTWAIN_AcquireFile(self.twain_source, "TEST.BMP", dtwain.DTWAIN_BMP, dtwain.DTWAIN_USELONGNAME, dtwain.DTWAIN_PT_DEFAULT, 1, False, True, 0)
def close(self):
print(self.dtwain_dll.DTWAIN_GetLastError())
self.dtwain_dll.DTWAIN_SysDestroy()
if __name__ == "__main__":
twain = TwainScanner()
twain.get_scan()
twain.close()
Please generate a full DTWAIN log (DTWAIN_SetTwainLog and log all the options available using DWTAIN_LOG_ALL and give a file name). This way, it will be more clear as to what is actually happening between the TWAIN data source manager, DTWAIN, and your application when you pull a card out.
The -1023 DTWAIN_ERR_UI_ERROR "Error in displaying Source User Interface" is given even if you are not showing a UI. It is given at the point where a TW_USERINTERFACE triplet is being sent to the TWAIN source manager, and that triplet contains the information on whether to start the acquisition process with or without a UI. Since that triplet sent to TWAIN failed, the error occurs. See here in the DTWAIN source code as to where this error occurs. Note the comment.
Quite possibly, the Plustek driver has custom capabilities and/or extended capabilities that are available that detects such errors. That is not possible for me to know this without a full TWAIN log available. Having said this, even if Plustek has custom capabilities, unless you have information from Plustek, I will not know what those custom capabilities actually do.
Since Twack32 has the same issue, this may be an OpenCV issue, which I have very little experience in. Maybe you can trace into where it is asserting in the CV code and go up the call stack to see where in your code it is attempting to access the array. From there, you could possibly do a check to ensure that the array is sized properly.
Thank you for the response. First log is a successful scan, second is one I have fail with the error pop-up. This time when I ran it I got -1039 DTWAIN_ERR_EXCEPTION_ERROR
If this doesn't provide any insight, I can try to reach out to Plustek about custom capabilities and update here. I fully expect to generate an error, but yes it would be nice to have this error not pop up with a separate window
- Can you start the log before you call DTWAIN_SelectSourceByName or better yet, right after DTWAIN_SysInitializeNoBlocking is called? It is when the source is open is where I can see the capability listing.
- Are you running the latest version (5.5.0) of DTWAIN?
- Also, it looks like your program didn't find the twresourcestrings_english.txt file, as there are some strings missing from your log. For example:
[2024-09-08 16:54:00] Thread [26532] =0 (TWRC_SUCCESS)
should be:
[2024-09-08 16:54:00] Thread [26532] Output: return code from DSM=0 (TWRC_SUCCESS)
Sorry, here's an updated log with logging enabled right after the initialization and the strings resource added to the folder.
This is on 5.4.8, I can update to 5.5
EDIT: Here's one with everything on 5.5.0 twain_log_550.txt
Looking at the capabilities, the device has the following:
CAP_CUSTOMBASE + 100
CAP_CUSTOMBASE + 111
CAP_CUSTOMBASE + 114
CAP_CUSTOMBASE + 115
CAP_CUSTOMBASE + 116
CAP_DEVICEEVENT
So 5 custom caps, and the CAP_DEVICEEVENT. The CAP_DEVICEEVENT may be of interest. See DTWAIN_GetDeviceNotifications to get a list of notifications that the device supports.
Also, what happens if you ran the programs that came with the Plustek scanner? How do they behave if the card is pulled out of the device?
I've received word with Plustek that this likely to be an issue with their driver and outside the scope of this library. I can update if I get more details, but as of now it's something they are looking into for us. Thank you.