-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f26c14
commit 3b141b6
Showing
9 changed files
with
393 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# =============================================================== | ||
# Author: Rodolfo Ferro Pérez | ||
# Email: [email protected] | ||
# Twitter: @FerroRodolfo | ||
# | ||
# Script: Video display script with two resolution sizes. | ||
# | ||
# ABOUT COPYING OR USING PARTIAL INFORMATION: | ||
# This script was originally created by Rodolfo Ferro. Any | ||
# explicit usage of this script or its contents is granted | ||
# according to the license provided and its conditions. | ||
# =============================================================== | ||
|
||
""" | ||
# =============================================================== | ||
# Author: Rodolfo Ferro Pérez | ||
# Email: [email protected] | ||
# Twitter: @FerroRodolfo | ||
# | ||
# Script: Video display script with two resolution sizes. | ||
# | ||
# ABOUT COPYING OR USING PARTIAL INFORMATION: | ||
# This script was originally created by Rodolfo Ferro. Any | ||
# explicit usage of this script or its contents is granted | ||
# according to the license provided and its conditions. | ||
# =============================================================== | ||
INSTRUCTIONS: | ||
Over de cam screen... | ||
1. Press <SPACEBAR> to change resolution. | ||
2. Press <ESC> to close the camera. | ||
""" | ||
|
||
import numpy as np | ||
import argparse | ||
import imutils | ||
import cv2 | ||
|
||
|
||
def resolution(cap, res=0): | ||
if res: | ||
cap.set(3, 640) | ||
cap.set(4, 480) | ||
return | ||
cap.set(3, 320) | ||
cap.set(4, 240) | ||
return | ||
|
||
|
||
print(__doc__) | ||
res, size = 0, ["320x240", "640x480"] | ||
cap = cv2.VideoCapture(0) | ||
resolution(cap, res) | ||
|
||
while(True): | ||
# Capture frame-by-frame: | ||
ret, frame = cap.read() | ||
|
||
# Display the resulting frame: | ||
cv2.imshow('Camera w/resolution {}'.format(size[res]), frame) | ||
|
||
# Look for pressed key: | ||
key = cv2.waitKey(10) | ||
if key == 27: | ||
break | ||
if key == 32: | ||
res += 1 | ||
res = res % 2 | ||
cv2.destroyWindow('Camera w/resolution {}'.format(size[(res + 1) % 2])) | ||
resolution(cap, res) | ||
|
||
# When everything done, release the capture: | ||
cap.release() | ||
cv2.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#include <sys/socket.h> | ||
#include <sys/types.h> | ||
#include <netinet/in.h> | ||
#include <arpa/inet.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
|
||
#define BUFFER_SZ 256 /*Tamaño de buffer*/ | ||
|
||
int sock_server(){ | ||
struct sockaddr_in serv_addr; | ||
int s, rc; | ||
|
||
serv_addr.sin_family = AF_INET; | ||
serv_addr.sin_port = htons(7500); | ||
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); | ||
|
||
// Si sock < 0 hay un error en la creación del socket: | ||
s = socket(AF_INET, SOCK_STREAM, 0); | ||
if (s < 0){ | ||
perror("Problema creando el socket"); | ||
exit(1); | ||
} | ||
|
||
// Bind del servidor al cliente: | ||
rc = bind(s, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); | ||
if (rc < 0){ | ||
perror("Problema en bind"); | ||
exit(1); | ||
} | ||
|
||
// Listen al cliente: | ||
rc = listen(s, 5); | ||
if (rc){ | ||
perror("Problema en listen"); | ||
exit(1); | ||
} | ||
|
||
return s; | ||
} | ||
|
||
pid_t create_child(){ | ||
pid_t pid; | ||
pid = fork(); | ||
if (pid == (pid_t)-1){ | ||
perror("Error en child"); | ||
exit(1); | ||
} | ||
return pid; | ||
} | ||
|
||
void send_file(int s, FILE *fp, char * filename){ | ||
// Enviamos archivo: | ||
char buffer[BUFFER_SZ]; | ||
int rc; | ||
fp = fopen(filename, "r"); | ||
|
||
while (!feof(fp)){ | ||
fscanf(fp, "%s", buffer); | ||
rc = write(s, buffer, BUFFER_SZ); | ||
bzero(buffer, BUFFER_SZ); | ||
} | ||
|
||
printf("The file was sent successfully!\n\n"); | ||
return; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int sock = 0, s, rc; | ||
char opt; | ||
char buffer[BUFFER_SZ]; | ||
char filename[BUFFER_SZ]; | ||
FILE *fp; | ||
pid_t child; | ||
|
||
// Inicio: | ||
printf("=== SERVER ===\n"); | ||
printf("Encargado del envío de archivos.\n"); | ||
|
||
// Creamos el socket: | ||
sock = sock_server(); | ||
|
||
// Ciclo de control: | ||
while (1){ | ||
// Aceptamos conexiones: | ||
s = accept(sock, NULL, NULL); | ||
if (s < 0){ | ||
perror("Problema aceptando conexión"); | ||
exit(1); | ||
} | ||
|
||
// Hacemos fork: | ||
child = create_child(); | ||
|
||
if (child == 0){ | ||
while (1) { | ||
rc = recv(s, &buffer, 1, 0); | ||
if(rc < 0) { | ||
perror("Error recibiendo opción"); | ||
exit(1); | ||
} | ||
|
||
opt = buffer[0]; | ||
printf("Opción recibida: %c\n", opt); | ||
switch (opt) { | ||
case '1': | ||
send_file(s, fp, "test.txt"); | ||
break; | ||
|
||
default: | ||
printf("HERE!\n"); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
// Cerramos socket: | ||
fclose(fp); | ||
close(sock); | ||
printf("Gracias por usar este servicio.\n"); | ||
// system("ls"); | ||
return 0; | ||
} |
Binary file not shown.
Oops, something went wrong.