by @mahaamesha
I want to measure length of fish. I use opencv to process the original image. The core of the result is based on image segmentation process.
-
Segmentation Process
The method that I use for segmentation is watershed algorithm. I also create some adaptation so that the result become more accurate (check segmentation.py). -
Measure Length Process
To measure the fish length, I try to use 3nd degree polynomial fitting. This make good result enough for sample image.The other method I have tried is skeleton method, but the skeleton not coverage edge-to-edge of the fish.
Fitting method can handle that, but the limitation is the function equation only give good result for landscape image.
-
Validating Process
To validate raw measurements, I use elimination of datum based on dynamic average value. This will remove small data whose value less thanunder_limit
. To handle close objects, generally segmentation will fail, so for large data whose value greater thanupper_limit
, I divide them by itfactor
. Checkvalidate_data(data)
in mafunction.py.This will give more accurate result if there are N > 1 data.
# This will be better if len(data) > 1 def validate_data(data): ... elif n > upper: factor = int(round(n / avg, 0)) copy.remove(n) for i in range(factor): avg = np.average(copy) copy.append(avg) ...
-
Further Process
I prepare the result to be saved as .json and .bin file. So, when I need to save the result to database, I can extract the measurement result from json file and the image from bin file.Bin file is encoded string from the image. I can save the encoded string to database. To show the image, I only need to decode the string.
To run this system, type this below in CMD.
-
For
v1.0.0
:python main.py -i img/lele.jpg -w 1
I set the default
-i
forlele.jpg
with-w 1
. So, I also run it bypython main.py
sometimes. -
For
v2.0.0
:python run.py
This is the result.