Hi,
you can get the RGB values of an image produced by Ip Camera for the control process ?
I have a timer and every 60 seconds do a image.
Script to timer
if (event.source.value == 30):
image = system.print.createImage(event.source.parent.parent.getComponent("CAMERA_IN"))
project.myfuncs.myimage(image)
In the Script Library i have create a myfuncs:
import datetime
import time
from java.io import *
from java.awt import *
from java.awt import Component
from java.awt import Color
from javax.imageio import ImageIO
from java.awt.image import BufferedImage
from java.io import ByteArrayOutputStream
from java.io import ByteArrayInputStream
from javax import imageio
from java.util import Arrays
# save image to folder
def myimage(image):
now = datetime.datetime.now()
mytime1 = now.strftime("%d-%m-%Y_%H-%M-%S")
mytime = str(mytime1)
baos = ByteArrayOutputStream()
ImageIO.write(image, "jpg", baos)
baos.flush()
imageInByte = baos.toByteArray()
baos.close()
system.file.writeFile(r"C:\\temp\\Test_"+mytime+".jpg", imageInByte)
mypixel(image)
# cicle image for all pixel to width and height
def mypixel(image):
w = image.getWidth()
h = image.getHeight()
pixelData = (w * h)
count = 0
for i in range(1, h):
for j in range(1, w):
count = count + 1
myList = getPixelData(image, i, j, count)
print "Value out: ", myList
# return rgb value
def getPixelData(image, x, y, count):
argb = image.getRGB(y, x) #image.getRGB(col, row)
alpha = (argb>>24) & 0xff
red = (argb>>16) & 0xff
gre = (argb>>8) & 0xff
blu = (argb) & 0xff
lux = (0.299 * red) + (0.587 * gre) + (0.114 * blu)
myList = [alpha, red, gre, blu, lux, count]
return myList
There is an error because I get:
Value out: [255, 255, 255, 255, 255.0, 76944]
can you help me, thanks