pk23 6 years ago
commit 87449e287e

@ -1,4 +1,5 @@
#include "HX711.h" #include <HX711.h>
HX711 scale; HX711 scale;
@ -48,12 +49,14 @@ void setup() {
} }
void loop() { void loop() {
Serial.print("one reading:\t"); //Serial.print("one reading:\t");
Serial.print(scale.get_units(), 1); //Serial.print(scale.get_units(), 1);
Serial.print("\t| average:\t"); //Serial.print("\t| average:\t");
if (Serial.available() > 0) {
Serial.println(scale.get_units(10), 1); Serial.println(scale.get_units(10), 1);
scale.power_down(); // put the ADC in sleep mode scale.power_down(); // put the ADC in sleep mode
delay(500); delay(100);
scale.power_up(); scale.power_up();
} }
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 281 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

@ -0,0 +1,100 @@
import cv2
import time
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler
from threading import Thread
cap = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX
list_img = cv2.imread('list.jpg')
list_img = cv2.resize(list_img,None,fx=0.8, fy=0.8, interpolation = cv2.INTER_CUBIC)
target_w = 50
candy1_img = cv2.imread('candy1.jpg')
factor = target_w / candy1_img.shape[0]
candy1_img = cv2.resize(candy1_img,None,fx=factor, fy=factor, interpolation = cv2.INTER_CUBIC)
candy2_img = cv2.imread('candy2.jpg')
factor = target_w / candy2_img.shape[0]
candy2_img = cv2.resize(candy2_img,None,fx=factor, fy=factor, interpolation = cv2.INTER_CUBIC)
candy3_img = cv2.imread('candy3.jpg')
factor = target_w / candy3_img.shape[0]
candy3_img = cv2.resize(candy3_img,None,fx=factor, fy=factor, interpolation = cv2.INTER_CUBIC)
candy4_img = cv2.imread('candy4.jpg')
factor = target_w / candy4_img.shape[0]
candy4_img = cv2.resize(candy4_img,None,fx=factor, fy=factor, interpolation = cv2.INTER_CUBIC)
img_list = [candy1_img, candy2_img, candy3_img, candy4_img]
IMG_W = 1280
IMG_H = 720
rect_w = 220
rect_h = 52
test_candy_stat = []
s = {}
s['img_idx'] = 0
s['loaded'] = 0
s['required'] = 4
test_candy_stat.append(s)
s = {}
s['img_idx'] = 1
s['loaded'] = 2
s['required'] = 2
test_candy_stat.append(s)
s = {}
s['img_idx'] = 2
s['loaded'] = 1
s['required'] = 6
test_candy_stat.append(s)
s = {}
s['img_idx'] = 3
s['loaded'] = 6
s['required'] = 9
test_candy_stat.append(s)
def new_order(params):
pass
def async_server_megahack(server):
server.serve_forever()
# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
def draw_rectangles(img, n):
for i in range(n):
cv2.rectangle(img, (IMG_W - 5 - rect_w,5 + (rect_h + 5)*i), (IMG_W - 5, 5 + (rect_h + 5)*i + rect_h), (255, 255, 255), -1)
def print_stats(img, stats):
# draw_rectangles(img, len(stats))
img[0:list_img.shape[0], IMG_W-list_img.shape[1]:IMG_W, :] = list_img[:]
for i in range(len(stats)):
cv2.putText(frame,str(stats[i]['loaded']),(IMG_W - 130,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
cv2.putText(frame,"/",(IMG_W - 90,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
cv2.putText(frame,str(stats[i]['required']),(IMG_W - 50,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
img[150+(rect_h + 5)*i:150+(rect_h + 5)*i + target_w, IMG_W-130-target_w-20:IMG_W-130-20, :] = img_list[stats[i]['img_idx']][:]
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
with SimpleXMLRPCServer(('localhost', 8000),
requestHandler=RequestHandler) as server:
server.register_introspection_functions()
# Register pow() function; this will use the value of
# pow.__name__ as the name, which is just 'pow'.
server.register_function(new_order)
# Run the server's main loop
t = Thread(target=async_server_megahack, args=(server,))
t.start()
while True:
ret, frame = cap.read()
frame = cv2.resize(frame,None,fx=2, fy=1.5, interpolation = cv2.INTER_CUBIC)
print_stats(frame, test_candy_stat)
print(frame.shape)
cv2.imshow("window", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
Loading…
Cancel
Save