# Industrial use of C ++ & OpenCV. Part 1: Problem statement and implementation methods

1. Statement of the problem and implementation methods;
2. Software recognition and electronics.

#### Engineer

To begin with, I'm a beginner engineer. As a student, I got a job as a programmer in a factory. The plant was engaged in the production of varnish-cap products. Simple: lids for seaming.

After some time, I got the task in a favorite format for many free format. I was allowed to dream up on this subject and after a while to provide my "misli" on this subject.

#### Fantasy

Counting the lids in the pile - it would seem that complicated? We take a nominal stack, put next to the stack, which we consider and “by eye (height)” determine 50 pieces or not 50.

It wasn’t there. This method has already been used in production, and the error was, I tell you, + \ - 2 pieces.

Due to the manufacturing process and cutting of the sealing gum, which is in each cover, the height could deviate by half a centimeter in both directions.

#### Misley

I immediately remembered that I had once dealt with OpenCV. I decided to use the OpenCV & C ++ bundle.

Several photographs were taken and several days spent trying to figure out how ... Because of the constantly changing lighting it was not clear how to isolate the part of interest from the overall picture. Then whipped up a closed “camera” with a controlled environment. By controlled environment, I mean the controlled location of the webcam and light source.

A fluorescent lamp was found in the neighboring market, which, for our purposes, was ideally suited.

#### First success

Finally, we started to get exactly those pictures that we wanted.

But then sleepless nights began, which flew by unnoticed ... There was more than enough enthusiasm. After a few days \ nights, I got the first result. The “algorithm” that I invented began to produce the correct values. After a preliminary demonstration, the higher authorities were given the go-ahead to continue this project.

The technological process of packaging products

This process consisted in the fact that after some manipulations by the “operator”, she got into a heat-sealing machine, which wrapped a film around the stack and baked a fixed time at high temperature.

The task was this: to count the number of products in a stack before they are packed and display the quantity in an understandable form for the operator. If there was “not 50” in the stack, regardless in which direction, the thermal pack should not have passed this stack onto the packaging.

On the right in the upright position you can see the “nominal” pack, with which everything was compared.

It can be seen above that the lamp was installed parallel to the cradle in which the product was placed for packaging.

The thermal packaging machine was controlled by a board based on Atmega8, which was made by my colleagues long before I met them.

Technical implementation We
decided to use FoxConn on Atome to perform the calculation. Some of these miles were purchased.

Permission to launch a thermal pack and a visual display of the number of products was hung on the Arduino Nano.

The camera was chosen Logitech 920e:

As a highlight, they took an LED strip with a plexiglass lens.

In the second part I will describe the search, counting algorithm and in detail I will talk about the electronics that were developed and manufactured.