Commit ebf0b15b authored by Ivan Tyagov's avatar Ivan Tyagov

Save frames locally.

parent 7aa390b0
...@@ -8,11 +8,14 @@ import numpy as np ...@@ -8,11 +8,14 @@ import numpy as np
import pymodbus import pymodbus
from pymodbus.client.sync import ModbusTcpClient as ModbusClient from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from time import sleep from time import sleep
from datetime import datetime
import os
import time
UNIT = 0x1 UNIT = 0x1
OSIE_PLC_ADDRESS = "localhost" # "192.168.0.48" for real machine OSIE_PLC_ADDRESS = "localhost" # "192.168.0.48" for real machine
#OSIE_PLC_ADDRESS = "192.168.0.48"
OSIE_PLC_PORT = 502 OSIE_PLC_PORT = 502
ROOT_FOLDER_PATH = "/mnt/flash"
def nothing(x): def nothing(x):
# any operation # any operation
...@@ -42,6 +45,22 @@ def openAndCloseAirValve(seconds=0.05): ...@@ -42,6 +45,22 @@ def openAndCloseAirValve(seconds=0.05):
client.write_coils(1, [False], unit=UNIT) client.write_coils(1, [False], unit=UNIT)
client.close() client.close()
def storeFrame(frame):
"""
Store a video frame in locally.
"""
folder_path = "%s/%s" %(ROOT_FOLDER_PATH, datetime.today().strftime('%Y-%m-%d'))
if not os.path.isdir(folder_path):
os.mkdir(folder_path)
millis = int(round(time.time() * 1000))
file_path = "%s/%s.jpg" %(folder_path, millis)
cv2.imwrite(file_path, frame)
#f = open(file_path, "w")
#f.write(file_content)
#f.close()
# start conveyor # start conveyor
setConveyorState(1) setConveyorState(1)
...@@ -93,14 +112,17 @@ while True: ...@@ -93,14 +112,17 @@ while True:
if len(approx) == 3: if len(approx) == 3:
cv2.putText(frame, "Triangle", (x, y), font, 1, (0, 0, 0)) cv2.putText(frame, "Triangle", (x, y), font, 1, (0, 0, 0))
storeFrame(frame)
openAndCloseAirValve() openAndCloseAirValve()
elif len(approx) == 4: elif len(approx) == 4:
cv2.putText(frame, "Rectangle", (x, y), font, 1, (0, 0, 0)) cv2.putText(frame, "Rectangle", (x, y), font, 1, (0, 0, 0))
storeFrame(frame)
openAndCloseAirValve() openAndCloseAirValve()
elif 10 < len(approx) < 20: elif 10 < len(approx) < 20:
cv2.putText(frame, "Circle-fire!", (x, y), font, 1, (0, 0, 0)) cv2.putText(frame, "Circle-fire!", (x, y), font, 1, (0, 0, 0))
storeFrame(frame)
openAndCloseAirValve() openAndCloseAirValve()
cv2.imshow("Frame", frame) cv2.imshow("Frame", frame)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment