Your error is probably due to OTB not being installed. You can check this by going to:
Processing > Options... > Providers
And look for
Orfeo Toolbox (Image analysis). If no paths are set then you may need to install it. A recent question was asked on how to install this: How to configure Orfeo toolbox in QGIS 2.18 on Windows 7 32-Bit?
Once it is installed, you could then run your code. However, there are some things to notice:
- Use either forward slashes or double-back slashes when defining paths.
- You may also need to include the extension of the file (e.g.
- Optional parameters (e.g. Validity Mask) need to be defined. But if you don't want to include it in the analysis, use
- There are two outputs: an image and a file (I specified it as a
.txt file). These also should be included.
This is the code I used to produce the two outputs:
processing.runalg("otb:unsupervisedkmeansimageclassification",'D:/data/sub_66.tif', 128, None, 100, 5, 1000, 0.0001, 'D:/data/sub_66k_means.tif', 'D:/data/sub_66k_centroid.txt')