Question

RasterObjectDetector Sample Preparer


Badge

I am trying to use the RasterObjectDetectorSamplePreparer and Model Trainer transformers. I created my positive and negative samples and also the annotations.txt file with the OpenCV tools. When I try to run my model, everything goes to "REJECTED".

 

I haven't found much documentation on this other than the blog: https://www.safe.com/blog/2019/01/fme-does-computer-vision/

@dmitribagh


20 replies

I'm having the same issue. I've tried to strip down the annotation file to just one image with one sample just to get it through, but it still chrashes. The file looks like this:

positiv\\img_00295.jpg 1 45 58 100 100

I'v tried different folder separators without any luck, Open CV still claims it can't open the image:

fme_rejection_message (encoded: UTF-8): Internal OpenCV Error has occured: b'Unable to open image: L:\\\\Machinelearning_FME2019\\\\\\xef\\xbb\\xbfpositiv\\\\\\\\img_00295.jpg\\r\\nOpenCV: terminate handler is called! The last OpenCV error is:\\r\\nOpenCV(3.4.3) Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat, file c:\\\\build\\\\3_4_winpack-build-win64-vc15\\\\opencv\\\\modules\\\\core\\\\src\\\\matrix.cpp, line 465\\r\\n'

Running on Windows 10.

 

 

Badge

Mine seems to be failing before looking at the images. Below is part of the log where all the red text starts to show up:

Storing feature(s) to FME feature store file `C:\\Users\\cforsyt1\\AppData\\Local\\Temp\\wb-cache-Pumpjack-PVvFdp\\Main_Creator -1 4 fo 0 CREATED 0 f727ed2395d4e726ce090801c62d517bec5308ce.ffsupdating'

Storing feature(s) to FME feature store file `C:\\Users\\cforsyt1\\AppData\\Local\\Temp\\wb-cache-Pumpjack-PVvFdp\\Main_RasterObjectDetectorSamplePrepar -1 2 fo 1 _lt_REJECTED_gt_ 0 1189a357367a4b728ab9393ca675663971ef0750.ffsupdating'

The below feature caused the translation to be terminated

Storing feature(s) to FME feature store file `H:\\OpenCV\\Pumpjack_log.ffs'

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Feature Type: `FEATURE_TYPE'

Attribute(encoded: UTF-8) : `_FME_HOME' has value `C:\\apps\\FME2019/'

Attribute(32 bit unsigned integer): `_creation_instance' has value `0'

Attribute(encoded: UTF-8) : `_negative_samples_dir' has value `C:\\Users\\cforsyt1\\AppData\\Roaming\\Safe Software\\FME\\Packages\\19238-win32\\transformers\\safe.robj-detect-pkg/Pumpjack\\Negative'

Attribute(encoded: UTF-8) : `_negative_samples_reuse' has value `Overwrite'

Attribute(encoded: UTF-8) : `_out_bg_desc_fname' has value `C:\\Users\\cforsyt1\\AppData\\Roaming\\Safe Software\\FME\\Packages\\19238-win32\\transformers\\safe.robj-detect-pkg/Pumpjack\\Negative\\bgd.txt'

Attribute(encoded: UTF-8) : `_out_vec_fname' has value `C:\\Users\\cforsyt1\\AppData\\Roaming\\Safe Software\\FME\\Packages\\19238-win32\\transformers\\safe.robj-detect-pkg/Pumpjack\\positives.vec'

Attribute(encoded: UTF-8) : `_positive_annotation_file' has value `C:\\Users\\cforsyt1\\AppData\\Roaming\\Safe Software\\FME\\Packages\\19238-win32\\transformers\\safe.robj-detect-pkg/annotations.txt'

Attribute(encoded: UTF-8) : `_positive_samples_height' has value `24'

Attribute(encoded: UTF-8) : `_positive_samples_num' has value `1'

Attribute(encoded: UTF-8) : `_positive_samples_width' has value `24'

Attribute(string) : `fme_feature_type' has value `Creator'

Attribute(string) : `fme_geometry' has value `fme_undefined'

Attribute(32 bit integer) : `fme_rejection_message' has value `2'

Attribute(string) : `fme_type' has value `fme_no_geom'

Coordinate System: `'

Geometry Type: IFMENull

===========================================================================

RasterObjectDetectorSamplePreparer_<REJECTED> (TeeFactory): RasterObjectDetectorSamplePreparer_<REJECTED>: Termination Message: 'RasterObjectDetectorSamplePreparer output a <Rejected> feature. To continue translation when features are rejected, change 'Workspace Parameters' > Translation > 'Rejected Feature Handling' to 'Continue Translation''

RasterObjectDetectorSamplePreparer_<REJECTED>: Termination Message: 'RasterObjectDetectorSamplePreparer output a <Rejected> feature. To continue translation when features are rejected, change 'Workspace Parameters' > Translation > 'Rejected Feature Handling' to 'Continue Translation''

Bridge failed to output feature on tag `PYOUTPUT'

RasterObjectDetectorSamplePreparer_PythonCaller (PythonFactory): PythonFactory failed to process feature

Userlevel 2
Badge +11

Hi @colin_forsyth,

try using relative paths - OpenCV is very unreliable in this respect, and we didn't have time yet to go through all the problems it has (unfortunately, there are more). Here is a screenshot of my dialog, which works.

My data files live with the workspace (or in some cases, in folders below the workspace). I understand it is less convenient than picking normal paths from the File Open dialog, we will try to resolve this issue in future releases.

Dmitri

Userlevel 2
Badge +11

Hi @hanste,

this is a bit different problem - I had it just last Friday - it happens when the coordinates of a box in the annotation file go beyond the image extents. I had quite a few of those (I am making my own annotation process for aerial imagery, I will share these results later, probably as another blog article). I ended up enforcing the annotation boxes never go outside of the pixel coordinates of the image with conditions in AttributeCreator (for example, if x < 0, set it to 0).

Dmitri

 

Badge

Hi @colin_forsyth,

try using relative paths - OpenCV is very unreliable in this respect, and we didn't have time yet to go through all the problems it has (unfortunately, there are more). Here is a screenshot of my dialog, which works.

My data files live with the workspace (or in some cases, in folders below the workspace). I understand it is less convenient than picking normal paths from the File Open dialog, we will try to resolve this issue in future releases.

Dmitri

Thanks Dmitri, I set mine up to be exactly the same, but still no luck. I noticed something though in the Translation Log. There is reference to opencv_createsamples. I have highlighted that in part of the Log that I have pasted below. If I go to the opencv folder on my computer, I don't see opencv_createsamples. Where can I get that? I searched on github and the opencv.org website, but haven't found it.

 

Executing:

C:\\apps\\FME2019/plugins\\opencv\\opencv_createsamples

Storing feature(s) to FME feature store file `C:\\Users\\cforsyt1\\AppData\\Local\\Temp\\wb-cache-Pumpjack-kgJPWd\\Main_RasterObjectDetectorSamplePrepar -1 2 fo 1 _lt_REJECTED_gt_ 0 1d4ccbfec9c12e92844e673fdd8a766e59173808.ffsupdating'

The below feature caused the translation to be terminated

Badge

Hi @colin_forsyth,

try using relative paths - OpenCV is very unreliable in this respect, and we didn't have time yet to go through all the problems it has (unfortunately, there are more). Here is a screenshot of my dialog, which works.

My data files live with the workspace (or in some cases, in folders below the workspace). I understand it is less convenient than picking normal paths from the File Open dialog, we will try to resolve this issue in future releases.

Dmitri

When I installed FME, it didn't setup OpenCV so I downloaded it from https://sourceforge.net/. I found out that the version of OpenCV that I installed (4.1.0) doesn't have opencv_createsamples.exe. It seems we have to use 3.4x versions.

I installed the older version of OpenCV, but it doesn't use the same folder structure that the transformer is looking for (C:\\apps\\FME2019\\plugins\\opencv\\opencv_createsamples).

Is there an FME install for OpenCV, or is there a way of modifying the transformer to point to the location of the installed opencv_createsample.exe file?

I really do have many potential uses for this at our company and would love to get it working.

Userlevel 2
Badge +11

When I installed FME, it didn't setup OpenCV so I downloaded it from https://sourceforge.net/. I found out that the version of OpenCV that I installed (4.1.0) doesn't have opencv_createsamples.exe. It seems we have to use 3.4x versions.

I installed the older version of OpenCV, but it doesn't use the same folder structure that the transformer is looking for (C:\\apps\\FME2019\\plugins\\opencv\\opencv_createsamples).

Is there an FME install for OpenCV, or is there a way of modifying the transformer to point to the location of the installed opencv_createsample.exe file?

I really do have many potential uses for this at our company and would love to get it working.

Hi @colin_forsyth,

you don't need to install anything to make it work - everything is included into FME. I still believe, it's the OpenCV code that requires a very accurate and specific parameter setting in order to work properly. We are currently fixing some problems, but there might be more.

 

 

Feel free to contact me directly at and we can try to figure out what is going on.

 

Dmitri

Userlevel 4
Badge +30

I'm having the same issue. I've tried to strip down the annotation file to just one image with one sample just to get it through, but it still chrashes. The file looks like this:

positiv\\img_00295.jpg 1 45 58 100 100

I'v tried different folder separators without any luck, Open CV still claims it can't open the image:

fme_rejection_message (encoded: UTF-8): Internal OpenCV Error has occured: b'Unable to open image: L:\\\\Machinelearning_FME2019\\\\\\xef\\xbb\\xbfpositiv\\\\\\\\img_00295.jpg\\r\\nOpenCV: terminate handler is called! The last OpenCV error is:\\r\\nOpenCV(3.4.3) Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat, file c:\\\\build\\\\3_4_winpack-build-win64-vc15\\\\opencv\\\\modules\\\\core\\\\src\\\\matrix.cpp, line 465\\r\\n'

Running on Windows 10.

 

 

Hi @hanste

 

I found the same error when the OpenCv try to open the image.

Userlevel 1
Badge +10

Hi @hanste

 

I found the same error when the OpenCv try to open the image.

Hi @danilo_fme! Does @dmitribagh's last reply on April 29th help? He seemed to encounter the same error when the coordinates of his annotation box went beyond the image extents.

Same problem here. Everything goes to rejected without a decent error message. I tried relative paths: no success. Since not all of the features have coordinates outside the image in the annotation file, my common sense knowledge says: there must be at least 1 feature that will pass. @SAFE: Is there news on this topic or a workarround. Must opencv be used to tackle this kind of object recognition problem?

Kind regards.

Same problem here. Everything goes to rejected without a decent error message. I tried relative paths: no success. Since not all of the features have coordinates outside the image in the annotation file, my common sense knowledge says: there must be at least 1 feature that will pass. @SAFE: Is there news on this topic or a workarround. Must opencv be used to tackle this kind of object recognition problem?

Kind regards.

from FME HUB:

Raster Object Detect Trainer changes

0.2.1

RasterObjectDetector Sample Preparer

Added annotation file verification and error checking

Preparer now drops all the bad lines found in the annotation files and dumps them into [annotation file name]_skipped.[ext] and all the kept lines that were used in [annotation file name]_kept.[ext]

Super!

Thus I tried to use the _kept file as input, still all features are rejected.

Badge

Hi everyone, I'm currently also looking into this. Using the only documentation I could find, the blogpost described in previous comments here. How do you draw the rectangles on the photos? Is this done with the "simple GUI" as described in the blogpost? When I try to start the "opencv_annotation.exe" the screen only flashes and nothing happens. Have tried to run the exe as administrator too.

Guessing I'm doing something elemtary wrong. Would be nice with more spesific documentation of the workflow!

Anyone? :)

Userlevel 2
Badge +11

Hi everyone, I'm currently also looking into this. Using the only documentation I could find, the blogpost described in previous comments here. How do you draw the rectangles on the photos? Is this done with the "simple GUI" as described in the blogpost? When I try to start the "opencv_annotation.exe" the screen only flashes and nothing happens. Have tried to run the exe as administrator too.

Guessing I'm doing something elemtary wrong. Would be nice with more spesific documentation of the workflow!

Anyone? :)

Hi @atle_hoidalen,

opencv_annotation.exe runs from a command line - start PowerShell or cmd on Windows or terminal on Mac and run it from there using the syntax from the blog article. If something goes wrong, feel free to contact me at .

 

Dmitri

 

Badge

Hi @atle_hoidalen,

opencv_annotation.exe runs from a command line - start PowerShell or cmd on Windows or terminal on Mac and run it from there using the syntax from the blog article. If something goes wrong, feel free to contact me at .

 

Dmitri

 

Hi Dmitri,

I did run it from command line, but still could not get it to work. I have posted my opinion about this feature here:

https://knowledge.safe.com/questions/96193/fme-2019-does-machine-learningcomputer-vision.html

As long as there is so little documentation and examples about this feature, and also, the workflow is as complicated as is, it is not something I will spend any more time on right now.

Badge +2

Hi, I tried my luck on this too and finally got the RasterObjectDetectorSamplePreparer working with a positive annotation file, manually constructed using the opencv_annotation.exe tool. It consisted of two samples only. After that I tried to generate the positive annotation file using an FME textfile writer, resulting in "exact" the same file. Using that file the RasterObjectDetectorSamplePreparer produced this Assertion failed error. Looking at the two files with the same contents, it showed that one was in UTF8 encoding, and the other (not working) was in UTF8+BOM encoding. Removing the UTF Byte Order Mark solved the Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x etc. error.

Badge +2

O forgot to tell, putting all files relating to one raster in one folder (and subfolders for negative and positive samples) seemed to help me avoiding relative/absolute paths trouble. However, now I am stuck with a generated custom object model xml and a RasterObjectDetector that is not outputting any detected rectangles (or giving me the error RasterObjectDetector (RasterObjectDetectFactory): Internal OpenCV fatal error has occured.

Badge

Not sure if this answer helps, but I also made my own annotations with FME in another workspace of satellite data. I got this error:

Internal OpenCV Error has occured: b'Unable to open image: .\\\xef\xbb\xbfGT_positives\\GT_Pos_P0030_00f6f968a795f68ae050120a080440dd.jpg\r\nOpenCV: terminate handler is called! The last OpenCV error is:\r\nOpenCV(3.4.3) Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat, file c:\\build\\3_4_winpack-build-win64-vc15\\opencv\\modules\\core\\src\\matrix.cpp, line 465\r\n'

Eventually I noticed this part:

.\\\xef\xbb\xbf

inn the path. I googled it and it had to do with the UTF Byte order Mark (UTF-BOM) (see this) . You can change thisin two ways that I know of:

 

1) Notepad ++: Set encoding to one of these two:

 

 

in the text file writer that writes the annotations if not through the openCV app, under parameters, set write  BOM to NO:

 

Hope this helps!

Badge +3

I have the same problem as all people above. I tried everything I could think of. relative paths, using very large positives with small boxes to ensure the box is within the jpg etc... etc...

 

Did Anybody get this to work? @dmitribagh​ 

Userlevel 2
Badge +11

I have the same problem as all people above. I tried everything I could think of. relative paths, using very large positives with small boxes to ensure the box is within the jpg etc... etc...

 

Did Anybody get this to work? @dmitribagh​ 

Hi @michiedem​ ,

 

I know it can be really frustrating. It took me quite some time to figure out how this works, and make it work consistently. The transformers we created are just the wrappers around openCV, we don't actually touch how they work. They only send commands to the library and relay back what the library reports.

Where do you actually have a problem? In one of the transformers or with annotation utility?

Here is a short video about annotating object if that helps - https://youtu.be/Zu3al5vzkbY

Also feel free to reach out directly to me (dmitri@safe.com) , I'll try to help you with this.

 

And yes, we have customers who made it work, but it never was easy. I am sorry about that. Maybe the community could request that Safe would invest some time into re-writing the buggy OpenCV code.

 

Dmitri

Badge +3

Hi @michiedem​ ,

 

I know it can be really frustrating. It took me quite some time to figure out how this works, and make it work consistently. The transformers we created are just the wrappers around openCV, we don't actually touch how they work. They only send commands to the library and relay back what the library reports.

Where do you actually have a problem? In one of the transformers or with annotation utility?

Here is a short video about annotating object if that helps - https://youtu.be/Zu3al5vzkbY

Also feel free to reach out directly to me (dmitri@safe.com) , I'll try to help you with this.

 

And yes, we have customers who made it work, but it never was easy. I am sorry about that. Maybe the community could request that Safe would invest some time into re-writing the buggy OpenCV code.

 

Dmitri

Hi Dmitri thank you! I had a lot of trouble getting the annotation file to work. After a lot of playing around with cache memmory and relative paths it works, hower the results are completely off and a bit weird.

 

I used a high resultion satellitephoto as input and the first attempt was to find active irrigations using some locations visible on the photo. The result was a radomn spot without irrigation. The next attempt I decided to try something easier: buildings. The result was again 1 area (there should be hundreds). Weirdly enough exactly the same area as the previous try with the irrigations. So the rresults seem way off.

Reply