I work on a project where I try to take an image of moving objects on a conveyor belt. The objects will be detected by a sensor.
The sensor is connected to the gpio via an optocoupler.
The programm is written in Python and the Camera is an USB Global Shutter from Hardkernel (the oCam-1CGN-U).
I use the libocam library from hardkernel for accessing the camera and taking pictures.
The whole setup is working, but not as I expected. The camera is taking pictures on signal, but the position of the objects changes between the pictures.
My expectation is that the object position in the image is nearly constant.
I've changed the setup from an Odroid to the Raspberry Pi, because the RPi.GPIO library supports hardware interrupts (not accessible on the Odroid because of WiringPi). But the changes were not noticeable.
I've also tried to reduce and increase the speed of the conveyor belt, but the result stays the same.
Here is my Code:
Code: Select all
import liboCams
from optparse import OptionParser
import RPi.GPIO as GPIO
from datetime import datetime
import time
import cv2
import os
from time import sleep
path = '/home/pi/Odroid_Scripte/Camera_GUI/pictures'
##Wiring Pi Setup
inputPin = 40
GPIO.setmode(GPIO.BOARD)
GPIO.setup(inputPin, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
Blc_Red = 9963790 #min: 0 max: 250 White Balance Red Component
Blc_Blue = 9963791 #min: 0 max: 250 White Balance Blue Component
Gain = 9963795 #min: 0 max: 255 Gain
Exp = 10094850 #min: 1 max: 625 Exposure (Absolute)
def cam_init():
parser = OptionParser()
parser.add_option("-a", "--alltest", dest="alltest",
action='store_true', help="test all resolution in playtime")
parser.add_option("-t", "--time", dest="playtime", default = 1, type = "int",
help="playtime for streaming [sec] intValue, 0 means forever")
parser.add_option("-i", "--index", dest="index", default = 0, type = "int",
help="index of resolusion mode")
(options, args) = parser.parse_args()
devpath = liboCams.FindCamera('oCam')
if devpath is None:
exit()
global test #Achtung Global
test = liboCams.oCams(devpath, verbose=1)
fmtlist = test.GetFormatList()
ctrlist = test.GetControlList()
test.Close()
if options.alltest is True:
len_range = range(len(fmtlist))
else:
if options.index >= len(fmtlist):
options.index = 0
len_range = { options.index }
for i in len_range:
test = liboCams.oCams(devpath)
test.Set(fmtlist[i])
name = test.GetName()
test.Start()
test.SetControl(Exp, 15)
test.SetControl(Gain, 128)
test.SetControl(Blc_Blue, 117)
test.SetControl(Blc_Red, 197)
test.GetFrame()
img_name = 0
def getimage(channel):
global img_name
frame = test.GetFrame()
pic = cv2.imwrite(os.path.join(path,'img'+str(img_name)+'.jpg'), frame)
img_name += 1
print "saved: "+'img'+str(img_name)+'.jpg'
cam_init()
GPIO.add_event_detect(inputPin, GPIO.RISING, callback= getimage, bouncetime = 500)
#GPIO.add_event_detect(inputPin, GPIO.RISING, callback= run_cap1)
try:
while True:
sleep(0.5)
except KeyboardInterrupt:
GPIO.cleanup()
print "\nBye"
Meanwhile i'm not sure how to continue.
Hopefully my description is understandable, if not feel free to ask.
Thank you for your support
Sincerely D3R0
Edit: I am working on a Raspberry Pi 3 with Python 2.7