Skip to content

Commit

Permalink
Added hcenter, vcenter, hshift, vshift parameters in servers configur…
Browse files Browse the repository at this point in the history
…ation files
  • Loading branch information
lebarsfa committed Aug 11, 2016
1 parent 711ee91 commit 0a91972
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 68 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
20
Improved compatibility with OpenCV 3.1.0.
Added hcenter, vcenter, hshift, vshift parameters in servers configuration files.

19
Improved Linux support.

Expand Down
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@
# sudo apt-get install build-essential
# in a terminal.
# You need to install OpenCV 2.4.9.
# For more information on the configuration used, see www.ensta-bretagne.fr/lebars/Share/Ubuntu.txt .
# Use dos2unix *.txt to ensure line endings are correct for Linux in the configuration files.
# In case of codecs problems, try with USE_ALTERNATE_RECORDING...

PROGS = RemoteWebcamMultiSrv RemoteWebcamSrv RemoteWebcamCli

CC = gcc
CXX = g++

#CFLAGS += -Wall -Winline -Wextra -g
CFLAGS += -Wall -O3
CFLAGS += -I. -I../OSUtils -I../Extensions/Img
#CFLAGS += -D _DEBUG -D _DEBUG_DISPLAY -D _DEBUG_MESSAGES
CFLAGS += -D DISABLE_GUI_REMOTEWEBCAMSRV -D DISABLE_GUI_REMOTEWEBCAMMULTISRV -D USE_ALTERNATE_RECORDING
#CFLAGS += -D _DEBUG -D _DEBUG_DISPLAY
#CFLAGS += -D _DEBUG_MESSAGES
#CFLAGS += -D DISABLE_GUI_REMOTEWEBCAMSRV -D DISABLE_GUI_REMOTEWEBCAMMULTISRV -D USE_ALTERNATE_RECORDING
CFLAGS += -D OPENCV249
#CFLAGS += -D OPENCV310

CXXFLAGS += $(CFLAGS) -fpermissive

LDFLAGS += -lopencv_core -lopencv_highgui -lopencv_imgproc
#LDFLAGS += -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_videoio
LDFLAGS += -lpthread -lrt -lm

default: $(PROGS)
Expand Down
6 changes: 4 additions & 2 deletions ReadMe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ Check also proxy settings of Internet Explorer, and any other installed browser.

It should work with the following software :
*** USER and DEVEL ***
_ Windows XP Professional SP3 32 bit/Windows 8 Professional 64 bit
_ Windows XP Professional SP3 32 bit/Windows 8.1 Professional 64 bit
_ Kinect v2 SDK (not available for Visual Studio 2008 and Windows XP)
*** DEVEL ***
_ Visual Studio 2008 SP1/Visual Studio 2012
_ OpenCV 2.4.9 (download http://www.ensta-bretagne.fr/lebars/Share/OpenCV2.4.9.zip and extract in C:)

It is also supposed to be compatible with Linux 2.6 with equivalent prerequisites, although not fully tested.
It is also supposed to be compatible with Linux with equivalent prerequisites, although not fully tested, see Makefile.

Restart the computer after installation.

The following are required sources dependencies :
_ ..\OSUtils : Windows/Linux abstraction layer (threads, network, serial port, time management...) as well as other useful functions.
_ ..\Extensions : some image functions.

Please do not try to build the program in a directory that contains commas! Mind the line endings in the configuration files depending on the OS (use e.g. the command dos2unix *.txt to convert line endings for Linux)!

See also https://github.com/ENSTABretagneRobotics/Android and http://www.ensta-bretagne.fr/lebars/utilities/
4 changes: 1 addition & 3 deletions RemoteWebcamCli/RemoteWebcamCli.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
% cli1address
127.0.0.1
%192.168.182.128
%192.168.1.10
%192.168.1.15
%192.168.1.107
% cli1port
4014
% videoimgwidth
Expand Down
4 changes: 4 additions & 0 deletions RemoteWebcamMultiSrv/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ int videoimgheight = 0;
int captureperiod = 0;
int timeout = 0;
BOOL bForceSoftwareResize = FALSE;
double hcenter = 0;
double vcenter = 0;
double hscale = 1;
double vscale = 1;
double angle = 0;
double hshift = 0;
double vshift = 0;
int bFlip = FALSE;
BOOL bUDP = FALSE;
int pixcolorchgthreshold = 0;
Expand Down
4 changes: 4 additions & 0 deletions RemoteWebcamMultiSrv/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ EXTERN_C int videoimgheight;
EXTERN_C int captureperiod;
EXTERN_C int timeout;
EXTERN_C BOOL bForceSoftwareResize;
EXTERN_C double hcenter;
EXTERN_C double vcenter;
EXTERN_C double hscale;
EXTERN_C double vscale;
EXTERN_C double angle;
EXTERN_C double hshift;
EXTERN_C double vshift;
EXTERN_C int bFlip;
EXTERN_C BOOL bUDP;
EXTERN_C int pixcolorchgthreshold;
Expand Down
66 changes: 36 additions & 30 deletions RemoteWebcamMultiSrv/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ int LoadConfig()
captureperiod = 40;
timeout = 5;
bForceSoftwareResize = 1;
hcenter = 0;//+videoimgwidth/2
vcenter = 0;//+videoimgheight/2
hscale = 1;
vscale = 1;
angle = 0*M_PI/180.0;
hshift = 0;//+videoimgwidth/2
vshift = 0;//+videoimgheight/2
bFlip = 0;
bUDP = 0;
pixcolorchgthreshold = 12;
Expand Down Expand Up @@ -52,13 +56,21 @@ int LoadConfig()
if (fgets3(file, line, sizeof(line)) == NULL) printf("Invalid configuration file.\n");
if (sscanf(line, "%d", &bForceSoftwareResize) != 1) printf("Invalid configuration file.\n");
if (fgets3(file, line, sizeof(line)) == NULL) printf("Invalid configuration file.\n");
if (sscanf(line, "%lf", &hcenter) != 1) printf("Invalid configuration file.\n");
if (fgets3(file, line, sizeof(line)) == NULL) printf("Invalid configuration file.\n");
if (sscanf(line, "%lf", &vcenter) != 1) printf("Invalid configuration file.\n");
if (fgets3(file, line, sizeof(line)) == NULL) printf("Invalid configuration file.\n");
if (sscanf(line, "%lf", &hscale) != 1) printf("Invalid configuration file.\n");
if (fgets3(file, line, sizeof(line)) == NULL) printf("Invalid configuration file.\n");
if (sscanf(line, "%lf", &vscale) != 1) printf("Invalid configuration file.\n");
if (fgets3(file, line, sizeof(line)) == NULL) printf("Invalid configuration file.\n");
if (sscanf(line, "%lf", &d0) != 1) printf("Invalid configuration file.\n");
angle = d0*M_PI/180.0;
if (fgets3(file, line, sizeof(line)) == NULL) printf("Invalid configuration file.\n");
if (sscanf(line, "%lf", &hshift) != 1) printf("Invalid configuration file.\n");
if (fgets3(file, line, sizeof(line)) == NULL) printf("Invalid configuration file.\n");
if (sscanf(line, "%lf", &vshift) != 1) printf("Invalid configuration file.\n");
if (fgets3(file, line, sizeof(line)) == NULL) printf("Invalid configuration file.\n");
if (sscanf(line, "%d", &bFlip) != 1) printf("Invalid configuration file.\n");
if (fgets3(file, line, sizeof(line)) == NULL) printf("Invalid configuration file.\n");
if (sscanf(line, "%d", &bUDP) != 1) printf("Invalid configuration file.\n");
Expand Down Expand Up @@ -409,6 +421,7 @@ THREAD_PROC_RETURN_VALUE handlecam(void* pParam)
{
double m[6]; // For rotation...
CvMat M = cvMat(2, 3, CV_64F, m); // For rotation...
double hcenter0 = 0, vcenter0 = 0, hshift0 = 0, vshift0 = 0;
int nbBytes = 0;
char szText[256];
unsigned int val = 0;
Expand Down Expand Up @@ -467,33 +480,29 @@ THREAD_PROC_RETURN_VALUE handlecam(void* pParam)
else resizedframe = frame;

EnterCriticalSection(&imageCS);
if ((hscale == 1)&&(vscale == 1)&&(angle == 0))
if ((hcenter == 0)&&(vcenter == 0)&&
(hscale == 1)&&(vscale == 1)&&(angle == 0)&&
(hshift == 0)&&(vshift == 0))
{
if (bFlip) cvFlip(resizedframe, image, 1); else cvCopy(resizedframe, image, 0);
}
else
{
// Create a map_matrix, where the left 2x2 matrix is the transform and the right 2x1 is the dimensions.
//double hscale = 0.5, vscale = 1.33*0.5;

hcenter0 = resizedframe->width*0.5+hcenter;
vcenter0 = resizedframe->height*0.5+vcenter;
hshift0 = resizedframe->width*0.5+hshift;
vshift0 = resizedframe->height*0.5+vshift;

m[0] = cos(angle)/hscale;
m[1] = sin(angle)/hscale;
m[3] = -sin(angle)/vscale;
m[4] = cos(angle)/vscale;
m[2] = (1-cos(angle)/hscale)*resizedframe->width*0.5-(sin(angle)/hscale)*resizedframe->height*0.5;
m[5] = (sin(angle)/vscale)*resizedframe->width*0.5+(1-cos(angle)/vscale)*resizedframe->height*0.5;
m[2] = (1-cos(angle)/hscale)*hshift0-(sin(angle)/hscale)*vshift0+hcenter0-hshift0;
m[5] = (sin(angle)/vscale)*hshift0+(1-cos(angle)/vscale)*vshift0+vcenter0-vshift0;
cvWarpAffine(resizedframe, image, &M, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP, cvScalarAll(0));

//double hscale = 1.33*0.5, vscale = 0.5;
//m[0] = hscale*cos(-angle);
//m[1] = hscale*sin(-angle);
//m[3] = vscale*-sin(-angle);
//m[4] = vscale*cos(-angle);
//m[2] = (1-hscale*cos(-angle))*resizedframe->width*0.5-hscale*sin(-angle)*resizedframe->height*0.5;
//m[5] = vscale*sin(-angle)*resizedframe->width*0.5+(1-vscale*cos(-angle))*resizedframe->height*0.5;
////cvGetQuadrangleSubPix(resizedframe, image, &M);
////cv2DRotationMatrix(cvPoint2D32f(resizedframe->width*0.5,resizedframe->height*0.5), -angle*180.0/M_PI, scale, &M);
//cvWarpAffine(resizedframe, image, &M, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, cvScalarAll(0));

if (bFlip) cvFlip(image, NULL, 1);
}
LeaveCriticalSection(&imageCS);
Expand Down Expand Up @@ -683,6 +692,7 @@ int main(int argc, char* argv[])
#endif // __ANDROID__
double m[6]; // For rotation...
CvMat M = cvMat(2, 3, CV_64F, m); // For rotation...
double hcenter0 = 0, vcenter0 = 0, hshift0 = 0, vshift0 = 0;
THREAD_IDENTIFIER handlecamThreadId;
char videorecordfilename[256];
int i = 0;
Expand Down Expand Up @@ -771,33 +781,29 @@ int main(int argc, char* argv[])
return EXIT_FAILURE;
}

if ((angle == 0)&&(hscale == 1)&&(vscale == 1))
if ((hcenter == 0)&&(vcenter == 0)&&
(hscale == 1)&&(vscale == 1)&&(angle == 0)&&
(hshift == 0)&&(vshift == 0))
{
if (bFlip) cvFlip(resizedframe, image, 1); else cvCopy(resizedframe, image, 0);
}
else
{
// Create a map_matrix, where the left 2x2 matrix is the transform and the right 2x1 is the dimensions.
//double hscale = 0.5, vscale = 1.33*0.5;

hcenter0 = resizedframe->width*0.5+hcenter;
vcenter0 = resizedframe->height*0.5+vcenter;
hshift0 = resizedframe->width*0.5+hshift;
vshift0 = resizedframe->height*0.5+vshift;

m[0] = cos(angle)/hscale;
m[1] = sin(angle)/hscale;
m[3] = -sin(angle)/vscale;
m[4] = cos(angle)/vscale;
m[2] = (1-cos(angle)/hscale)*resizedframe->width*0.5-(sin(angle)/hscale)*resizedframe->height*0.5;
m[5] = (sin(angle)/vscale)*resizedframe->width*0.5+(1-cos(angle)/vscale)*resizedframe->height*0.5;
m[2] = (1-cos(angle)/hscale)*hshift0-(sin(angle)/hscale)*vshift0+hcenter0-hshift0;
m[5] = (sin(angle)/vscale)*hshift0+(1-cos(angle)/vscale)*vshift0+vcenter0-vshift0;
cvWarpAffine(resizedframe, image, &M, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP, cvScalarAll(0));

//double hscale = 1.33*0.5, vscale = 0.5;
//m[0] = hscale*cos(-angle);
//m[1] = hscale*sin(-angle);
//m[3] = vscale*-sin(-angle);
//m[4] = vscale*cos(-angle);
//m[2] = (1-hscale*cos(-angle))*resizedframe->width*0.5-hscale*sin(-angle)*resizedframe->height*0.5;
//m[5] = vscale*sin(-angle)*resizedframe->width*0.5+(1-vscale*cos(-angle))*resizedframe->height*0.5;
////cvGetQuadrangleSubPix(resizedframe, image, &M);
////cv2DRotationMatrix(cvPoint2D32f(resizedframe->width*0.5,resizedframe->height*0.5), -angle*180.0/M_PI, scale, &M);
//cvWarpAffine(resizedframe, image, &M, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, cvScalarAll(0));

if (bFlip) cvFlip(image, NULL, 1);
}

Expand Down
11 changes: 11 additions & 0 deletions RemoteWebcamMultiSrv/RemoteWebcamMultiSrv.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
% camid (0..9) or a video filename
0
%Kinect2Color
%Kinect2Depth
%Kinect2Infrared
% srvport
4014
% videoimgwidth
Expand All @@ -14,12 +17,20 @@
5
% bForceSoftwareResize
1
% hcenter
0
% vcenter
0
% hscale
1
% vscale
1
% rotation angle (in deg)
0
% hshift
0
% vshift
0
% bFlip
0
% bUDP
Expand Down
4 changes: 4 additions & 0 deletions RemoteWebcamSrv/Globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ int videoimgheight = 0;
int captureperiod = 0;
int timeout = 0;
BOOL bForceSoftwareResize = FALSE;
double hcenter = 0;
double vcenter = 0;
double hscale = 1;
double vscale = 1;
double angle = 0;
double hshift = 0;
double vshift = 0;
int bFlip = FALSE;
BOOL bUDP = FALSE;
int pixcolorchgthreshold = 0;
Expand Down
4 changes: 4 additions & 0 deletions RemoteWebcamSrv/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ EXTERN_C int videoimgheight;
EXTERN_C int captureperiod;
EXTERN_C int timeout;
EXTERN_C BOOL bForceSoftwareResize;
EXTERN_C double hcenter;
EXTERN_C double vcenter;
EXTERN_C double hscale;
EXTERN_C double vscale;
EXTERN_C double angle;
EXTERN_C double hshift;
EXTERN_C double vshift;
EXTERN_C int bFlip;
EXTERN_C BOOL bUDP;
EXTERN_C int pixcolorchgthreshold;
Expand Down
Loading

0 comments on commit 0a91972

Please sign in to comment.