Raspberry Pi camera module

Post your Gambas programming questions here.
sony
Posts: 32
Joined: Wednesday 14th June 2017 12:28am

Re: Raspberry Pi camera module

Post by sony »

Hi Charlie,
It's like a beginner tech to teacher :)
I think you must log in to root

1st problem, you should have 'param.par' file in the home folder.
par_file_folder.PNG
par_file_folder.PNG (76.64 KiB) Viewed 12051 times
2nd problem, you must create the 'tmp1' ram drive
create_RAM_drive.PNG
create_RAM_drive.PNG (37.05 KiB) Viewed 12051 times
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Raspberry Pi camera module

Post by cogier »

OK. I suggest you add the following code at line 79 to create 'param.par' if it does not exist
If Not Exist(User.home &/ "param.par") Then File.Save(User.home &/ "param.par", "")


I changed all references to the RamDrive to /tmp (not /tmp1) and added the following 'Sub' which I took from 'PiCam'.
Public Sub CreateRAMDrive()                                         'To create a RAM drive to hold the SSH Preview picture
Dim sFstab As String                                                'To store the details in the fstab file

If Not Exist("/var/tmp") Then Mkdir "/var/tmp"                      'Does this folder exist, if not create it

sFstab = File.Load("/etc/fstab")                                    'Load the contents of fstab into sFstab

If Not InStr(sFstab, "tmpfs /var/tmp tmpfs nodev,nosuid,size=3M 0 0") Then 'If the string we need to create the 3Meg RAM drive is not there then..
  sFstab &= "\ntmpfs /var/tmp tmpfs nodev,nosuid,size=3M 0 0\n"     'Add the string to the end of the file
  File.Save(User.Home &/ "fstab", sFstab)                           'Save the file to the Home folder
  Shell "sudo mv ~/fstab /etc/fstab"                                'Move the file to the 'etc' folder
  Shell "sudo mount -a"                                             'Mount all drives including our new one
Endif

End
Then call that the 'Sub' : -
Public Sub Form_Open()

CreateRAMDrive

If (wiringPiSetup() = -1).............
I get a picture taken in the RamDrive but I am not sure what is supposed to happen next, I have changed all the values and clicked everything but nothing seems to happen. Are you still trying to display video output?
sony
Posts: 32
Joined: Wednesday 14th June 2017 12:28am

Re: Raspberry Pi camera module

Post by sony »

It's about how to setting the parameter. For test just add a button with code like picture below:
new_button.PNG
new_button.PNG (13.86 KiB) Viewed 12041 times
IF you run the program then click the button will shot the camera like below:
sample1.PNG
sample1.PNG (79.43 KiB) Viewed 12041 times
Now you can fill the parameter. Size mean size area copied of image from left to right area, Pos mean position area copied of image from left to right area.

for example if you want capture the position of image with the writing SIMATIC you must set the paramater Pos with value like image below,
press copy button you will copy the necessary position to right area.
samplepos10-65.PNG
samplepos10-65.PNG (95.85 KiB) Viewed 12041 times
After that if you press 'calculate' will count differential pixel color in the image copied area.

If you give different value in Pos parameter and try step like above will give different pixel count. Just if trigger active and picture shot by camera automatically and if Actual pixel count less then limit the output will be energize.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Raspberry Pi camera module

Post by cogier »

Matt and I have done some work for you. Have a look at the attached program.

When you want to 'Copy' just use the mouse to select the area to copy and when you release the mouse button it will copy across automatically.

Hope you like it.
PiCamera.png
PiCamera.png (187 KiB) Viewed 12033 times
PiCamera.tar.gz
(36.89 KiB) Downloaded 509 times
sony
Posts: 32
Joined: Wednesday 14th June 2017 12:28am

Re: Raspberry Pi camera module

Post by sony »

my goal to make this project is to stop the conveyor if PiCam detected products that are not printed with barcode images automatically. See my block diagram below.
image001.PNG
image001.PNG (36.6 KiB) Viewed 12028 times
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Raspberry Pi camera module

Post by cogier »

Have a look at the attached program to see if it helps you.

It requires the installation of 'zbar-tools' and the use of a standard webcam NOT a Raspberry Pi camera.

Tested on Raspberry Pi 3 and Linux Mint 18.3.

It will scan a barcode and show the output.
read.png
read.png (398.15 KiB) Viewed 12017 times
BarcodeReader.tar.gz
(13.28 KiB) Downloaded 518 times
sony
Posts: 32
Joined: Wednesday 14th June 2017 12:28am

Re: Raspberry Pi camera module

Post by sony »

Hi Charlie,
It looks like an advanced level :o . My project is running with a running conveyor as well, so I decided to only detect barcode images, not barcode data.
The first time I also tried to use the webcam but could not capture the image object well. With PiCam I can take pictures of moving objects even with blurred results.
You can imagine if many moving box to detected and then the RPi must able to detect wich box with or without barcode sticker.
Any idea?
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Raspberry Pi camera module

Post by cogier »

I think that if the bar code is in the same position on the boxes then the camera will be able to read the bar code and that will tell your program that there is a bar code on the box. It does not matter that the program reads the actual bar code only that it exists. Change sOutput to ="Yes" and you will get a "Yes" every time there is a bar code.

It must be worth a try.
It looks like an advanced level :o
There is not very much code there if you strip out the code I used to make it look pretty. Have you run the program?
sony
Posts: 32
Joined: Wednesday 14th June 2017 12:28am

Re: Raspberry Pi camera module

Post by sony »

Hello,
Beside reading the barcode image, how to detect there is text printed at the box or not
expcode.PNG
expcode.PNG (102.26 KiB) Viewed 11988 times
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Raspberry Pi camera module

Post by stevedee »

sony wrote: Friday 23rd February 2018 6:17am ...how to detect there is text printed at the box or not...
I think any solution will be relatively complicated, and if this was a real industrial conveyor system, you would need a proper rugged transducer/reader, rather than a RaspiCam.

But as an academic exercise, you would need to use some form of image recognition. Perhaps you could simply grab an image at the right time, and find a rectangular area within the image where all sides where 'white' (the pixel average value of this white border would form your reference level). Then you could check the average intensity based upon all pixels within this rectangle. If the average was considerably lower than your reference level (the 'white' sides), then it is likely that the white box contains printed text (...or smudged ink, or a dirty mark, or a house fly...).

Or you could use image or text recognition by using someone's library (probably written in C or maybe Python) or fully research the subject and write your own for Gambas (very time consuming).
Post Reply