I am working on a project wherein an image is transferred from a smartphone via bluetooth and ocr is performed on the image.Now to automate the process I have used a bash script to check whether the image is present in the bluetooth folder or not ,but even during the transfer (before 100% ) raspberry pi detects that image is present and it leads to incorrect predictions

So is there any way I can check the transfer process and initiate the ocr only after the image has been completely transferred.

  • 1
    Welcome! What operating system, Raspbian Stretch? How do you control the file transfer, by a python script? Can you show us the code? Please edit your question and do not add these details as comment. – Fabian Apr 2 '18 at 16:22

This is almost certainly because the file is still transferring when it is detected in the bluetooth folder. I'm assuming you have no scriptable control over the transfer of the file, ie. it is pushed from the smartphone not using any script. In that case what you could do is use inotifywait (from the inotify-tools package) to monitor the file-system events on the bluetooth folder and then if you see close_write (or create) events you could see if you could write a script to react on those close_write (or create) events rather than just looking at directory contents every so often.

Here's one way to script it:

  1. Create a named pipe to store the filenames to be processed.
  2. Run a command in the background to constantly read from the named pipe and process newly created files.
  3. Call inotifywait to react to create events on the bluetooth folder and then send the newly created files to the named pipe.

So ...

cd bluetooth-dir mkfifo image_pipe process_images < image_pipe & inotifywait -mq -e create --format %f . > image_pipe

where your process_images function is something like:

process_images() { while read filename; do ... done }

  • in the command line while executing inotifywait -mq -e create --format %f . > image_pipe I get the following error bash: image_pipe: Permission denied and can you please provide an easier explanation for the solution – Tejas Hegde Apr 3 '18 at 13:05
  • Make sure your user has permissions to write in the bluetooth-dir or just create bypass the named pipe, something like: inotifywait -mq -e create --format %f . | process_images – John Hawthorne Apr 3 '18 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.