김민석

final

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import socket \n",
"import select \n",
"import os "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def removeAllFile(filePath):\n",
" if os.path.exists(filePath):\n",
" for file in os.scandir(filePath):\n",
" os.remove(file.path)\n",
" return 'Remove All File'\n",
" else:\n",
" return 'Directory Not Found'\n",
"\n",
"print(removeAllFile('/home/pi/capdesign/frames'))\n",
"address = ('192.168.51.1', 8083)\n",
"sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n",
"sock.bind(address)\n",
"\n",
"while True:\n",
" data, addr = sock.recvfrom(1024)\n",
" if data:\n",
" data = data.decode()\n",
" print(\"filename\", data)\n",
" file_name = data.strip()\n",
" \n",
" f = open('frames/{}'.format(file_name), 'wb')\n",
" \n",
" while True:\n",
" ready = select.select([sock], [], [], 3)\n",
" if ready[0]:\n",
" data, addr = sock.recvfrom(1024)\n",
" if(data == \"FINISH\".encode('utf-8')):\n",
" f.close()\n",
" break\n",
" else:\n",
" f.write(data) "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
{
"CurrentProjectSetting": null
}
\ No newline at end of file
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\index.js",
"PreviewInSolutionExplorer": false
}
\ No newline at end of file
No preview for this file type
No preview for this file type
This diff could not be displayed because it is too large.
from picamera import PiCamera
from time import sleep
import socket
import cv2
buf = 1024
address = ('192.168.50.1', 8080)
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
print('Sender Socket Initialized')
except:
print("fail")
#camera = PiCamera()
vid = cv2.VideoCapture(-1)
i = 0
while(True):
ret, frame = vid.read()
cv2.imshow('frame', frame)
cv2.imwrite('/home/pi/Desktop/frames/{}.jpg'.format(i), frame)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto('{}.jpg'.format(i).encode(), address)
print('sending file_name to server....')
f = open('/home/pi/Desktop/frames/{}.jpg'.format(i), 'rb')
i += 1
if(f):
print("yes")
data = f.read(buf)
while(data):
if(s.sendto(data,address)):
print('sending...')
data = f.read(buf)
s.close()
if cv2.waitKey(1) & 0xFF == ord('q'):
break
vid.release()
cv2.destroyAllWindows()
\ No newline at end of file
......@@ -2,6 +2,11 @@ let express = require('express');
let app = express();
let path = require('path');
let fs = require('fs');
let frameCount = 0;
const dir = './frames'
app.use('/js', express.static(__dirname + '/node_modules/jquery/dist')); // redirect JS jQuery
app.use('/frames', express.static(__dirname + '/frames'));
app.listen(3000, function(){
console.log("hosting server start");
......@@ -13,11 +18,12 @@ app.get('/', function(req, res){
});
app.get('/frames', function(req, res){
fs.readFile('./frames/1.jpg', function(error, data){
fs.readdir(dir, (err, files)=>{
frameCount = files.length;
})
fs.readFile('./frames/' + String(frameCount-1)+'.jpg', function(error, data){
res.writeHead(200, {'Content-Type' : 'text/html'});
res.end(data);
})
});
app.use('/js', express.static(__dirname + '/node_modules/jquery/dist')); // redirect JS jQuery
app.use('/frames', express.static(__dirname + '/frames'));
......
This diff could not be displayed because it is too large.
This file is too large to display.
This file is too large to display.
No preview for this file type
This file is too large to display.
from picamera import PiCamera
from time import sleep
import socket
import cv2
capture = cv2.VideoCapture(0)
capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
i = 0
finish_msg = "FINISH"
buf = 1024
address = ('192.168.50.1', 8080)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while cv2.waitKey(33) < 0:
ret, frame = capture.read()
# cv2.imshow('frame', frame) # img를 보여주는 곳
cv2.imwrite('frames/{}.jpg'.format(i), frame)
try:
file_name = str(i) + '.jpg'
sock.sendto(file_name.encode('utf-8'), address)
f = open('frames/{}'.format(file_name), 'rb')
data = f.read(buf)
print(file_name, "Sending....")
while(data):
sock.sendto(data, address)
data = f.read(buf)
if(sock.sendto(finish_msg.endcode('utf-8'), address)):
print("Finish message send")
print(file_name, "send finish")
f.close()
except:
print("error")
i+=1
capture.release()
cv2.destroyAllWindows()
\ No newline at end of file
import socket
import select
import os
def removeAllFile(filePath):
if os.path.exists(filePath):
for file in os.scandir(filePath):
os.remove(file.path)
return 'Remove All File'
else:
return 'Directory Not Found'
print(removeAllFile('/home/pi/capdesign/frames'))
address = ('192.168.50.1', 8080)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(address)
sock2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
send_address = ('192.168.51.1', 8083)
buf = 1024
finish_msg = "FINISH"
while True:
data, addr = sock.recvfrom(1024)
if data:
print("filename", data)
file_name = data.strip()
f = open('frames/{}'.format(file_name), 'wb')
while True:
ready = select.select([sock], [], [], 3)
if ready[0]:
data, addr = sock.recvfrom(1024)
if(data == "FINISH".encode('utf-8')):
print("Receivin {} FINISH".format(file_name))
f.close()
break
else:
f.write(data)
# send to uav2
try:
print(file_name)
sock2.sendto(file_name.encode('utf-8'), send_address)
print("file name sending success")
f = open('frames/{}'.format(file_name), 'rb')
data = f.read(1024)
print(file_name, "Sending...")
while(data):
try:
sock2.sendto(data, send_address)
except:
print("sock2 makes problem")
try:
data = f.read(1024)
except:
print("data read makes problem")
print("data sending finished")
if(sock2.sendto(finish_msg.encode('utf-8'), send_address)):
print('Finish message send')
print(file_name, "send finish")
f.close()
except:
print("sending error")
sock.close()
sock2.close()
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import socket \n",
"import select \n",
"import os "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def removeAllFile(filePath):\n",
" if os.path.exists(filePath):\n",
" for file in os.scandir(filePath):\n",
" os.remove(file.path)\n",
" return 'Remove All File'\n",
" else:\n",
" return 'Directory Not Found'\n",
"\n",
"print(removeAllFile('/home/pi/capdesign/frames'))\n",
"address = ('192.168.51.1', 8083)\n",
"sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n",
"sock.bind(address)\n",
"\n",
"while True:\n",
" data, addr = sock.recvfrom(1024)\n",
" if data:\n",
" data = data.decode()\n",
" print(\"filename\", data)\n",
" file_name = data.strip()\n",
" \n",
" f = open('frames/{}'.format(file_name), 'wb')\n",
" \n",
" while True:\n",
" ready = select.select([sock], [], [], 3)\n",
" if ready[0]:\n",
" data, addr = sock.recvfrom(1024)\n",
" if(data == \"FINISH\".encode('utf-8')):\n",
" f.close()\n",
" break\n",
" else:\n",
" f.write(data) 2"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import socket
import select
import os
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('192.168.50.1', 8080))
address = ('192.168.50.1', 8080)
# In[ ]:
def removeAllFile(filePath):
if os.path.exists(filePath):
for file in os.scandir(filePath):
os.remove(file.path)
return 'Remove All File'
else:
return 'Directory Not Found'
print(removeAllFile('/home/pi/capdesign/frames'))
address = ('192.168.51.1', 8083)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(address)
while True:
data, addr = sock.recvfrom(1024)
if data:
data = data.decode()
print("filename", data)
file_name = data.strip()
......@@ -18,10 +38,9 @@ while True:
ready = select.select([sock], [], [], 3)
if ready[0]:
data, addr = sock.recvfrom(1024)
f.write(data)
else:
print("Finish", file_name)
if(data == "FINISH".encode('utf-8')):
f.close()
break
sock.close()
else:
f.write(data)
......