Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dyncam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rene Kolling
dyncam
Commits
bf7f78b9
Commit
bf7f78b9
authored
Apr 1, 2021
by
Rene
Browse files
Options
Downloads
Patches
Plain Diff
Rectangle searcher II zum laufen gebracht
parent
ca214595
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
dyncam
+0
-0
0 additions, 0 deletions
dyncam
dyncam.c
+142
-9
142 additions, 9 deletions
dyncam.c
with
142 additions
and
9 deletions
dyncam
+
0
−
0
View file @
bf7f78b9
No preview for this file type
This diff is collapsed.
Click to expand it.
dyncam.c
+
142
−
9
View file @
bf7f78b9
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<stdint.h>
#include
<inttypes.h>
#include
<X11/Xlib.h>
...
...
@@ -26,7 +28,8 @@ extern void throwWarning (char *warningMSG);
#define WARN throwWarning
extern
unsigned
long
extractHexFromString
(
char
*
hexString
);
extern
unsigned
long
extractIntFromString
(
char
*
intString
);
extern
rectangle
searchForColorRect
(
unsigned
long
color
,
XImage
*
image
,
unsigned
width
,
unsigned
height
);
extern
rectangle
searchForColorRect
(
uint32_t
color
,
XImage
*
image
,
unsigned
width
,
unsigned
height
);
extern
rectangle
searchForColorRectII
(
uint32_t
color
,
XImage
*
image
,
unsigned
width
,
unsigned
height
);
extern
unsigned
long
lookingForColorOnCoordinate
(
XImage
*
image
,
unsigned
x
,
unsigned
y
);
extern
void
evaluateArguments
(
int
argc
,
char
**
argv
);
...
...
@@ -95,8 +98,11 @@ int main (int argc, char **argv)
searchColor
=
lookingForColorOnCoordinate
(
image
,
x
,
y
);
colorParam
=
True
;
}
if
(
colorParam
)
searchForColorRect
(
searchColor
,
image
,
width
,
height
);
if
(
colorParam
)
{
//searchForColorRect(searchColor, image, width,height);
searchForColorRectII
(
searchColor
,
image
,
width
,
height
);
}
image
->
f
.
destroy_image
(
image
);
XDestroyWindow
(
display
,
window
);
...
...
@@ -163,7 +169,7 @@ void evaluateArguments (int argc, char **argv)
continue
;
}
if
(
!
strcmp
(
OPTION
,
"-f
ou
nd"
)
||
!
strcmp
(
OPTION
,
"-f"
))
{
if
(
!
strcmp
(
OPTION
,
"-f
i
nd"
)
||
!
strcmp
(
OPTION
,
"-f"
))
{
if
(
pickColor
)
{
WARN
(
"Pick excludes -found!"
);
NEXTOPT
;
...
...
@@ -190,16 +196,140 @@ void evaluateArguments (int argc, char **argv)
}
}
/* Pixels are getting printet by ff blue ff00 green ff00000 red */
rectangle
searchForColorRect
(
unsigned
long
color
,
XImage
*
image
,
unsigned
width
,
unsigned
height
)
{
rectangle
searchForColorRectII
(
uint32_t
color
,
XImage
*
image
,
unsigned
width
,
unsigned
height
)
{
rectangle
rect
;
int
count
=
0
;
uint32_t
extractedColor
;
int
*
countX
=
malloc
(
sizeof
(
int
)
*
width
);
int
*
countY
=
malloc
(
sizeof
(
int
)
*
height
);
Bool
foundColor
=
False
;
for
(
int
i
=
0
;
i
<
width
;
i
++
)
{
countX
[
i
]
=
0
;
}
for
(
int
i
=
0
;
i
<
height
;
i
++
)
{
countY
[
i
]
=
0
;
}
for
(
int
pixY
=
0
;
pixY
<
height
;
pixY
++
)
{
for
(
int
pixX
=
0
;
pixX
<
width
;
pixX
++
)
{
extractedColor
=
(
unsigned
char
)
image
->
data
[
count
];
extractedColor
+=
(
unsigned
char
)
image
->
data
[
count
+
1
]
*
256
;
extractedColor
+=
(
unsigned
char
)
image
->
data
[
count
+
2
]
*
256
*
256
;
if
(
color
==
extractedColor
)
{
countX
[
pixX
]
++
;
countY
[
pixY
]
++
;
foundColor
=
True
;
}
count
+=
4
;
}
}
if
(
!
foundColor
)
{
ERROR
(
"Farbe wurde nicht gefunden"
);
}
foundColor
=
False
;
int
rowMin
=
0
;
int
rowMax
=
0
;
int
columnMin
=
0
;
int
columnMax
=
0
;
int
rowMiddle
;
int
columnMiddle
;
for
(
int
row
=
0
;
row
<
height
;
row
++
)
{
if
(
countY
[
row
]
>
rowMax
)
{
rowMax
=
countY
[
row
];
}
if
(
countX
[
row
]
==
0
||
countX
[
0
]
<
rowMin
)
{
rowMin
=
countX
[
row
];
}
}
for
(
int
column
=
0
;
column
<
width
;
column
++
)
{
if
(
countX
[
column
]
>
columnMax
)
{
columnMax
=
countX
[
column
];
}
if
(
countX
[
column
]
==
0
||
countX
[
0
]
<
columnMin
)
{
columnMin
=
countX
[
column
];
}
}
rowMiddle
=
(
rowMax
-
rowMin
)
/
2
;
columnMiddle
=
(
columnMax
-
columnMin
)
/
2
;
for
(
int
row
=
0
;
row
<
height
;
row
++
)
{
if
(
countY
[
row
]
>
rowMiddle
)
{
if
(
!
foundColor
)
{
rect
.
y
=
row
;
foundColor
=
True
;
rect
.
height
=
1
;
}
else
{
rect
.
height
++
;
}
}
}
foundColor
=
False
;
for
(
int
column
=
0
;
column
<
width
;
column
++
)
{
if
(
countX
[
column
]
>
columnMiddle
)
{
if
(
!
foundColor
)
{
rect
.
x
=
column
;
foundColor
=
True
;
rect
.
width
=
1
;
}
else
{
rect
.
width
++
;
}
}
}
if
(
debug
)
{
printf
(
"DEBUG: row Max is %d and column max is %d
\n
"
,
rowMax
,
columnMax
);
printf
(
"DEBUG: row middle is %d and column middle is %d
\n
"
,
rowMiddle
,
columnMiddle
);
/*
for(int i = 0; i < width ;i++){
if(!(countX[i] == 0))
printf("column: %d contains: %d\n", i, countX[i]);
}
for(int i = 0; i < height ;i++){
if(!(countY[i] == 0))
printf("row: %d contains: %d\n", i, countY[i]);
} */
}
printf
(
"%d %d %d %d
\n
"
,
rect
.
x
,
rect
.
y
,
rect
.
width
,
rect
.
height
);
return
rect
;
}
/* Pixels are getting printet by ff blue ff00 green ff0000 red */
rectangle
searchForColorRect
(
uint32_t
color
,
XImage
*
image
,
unsigned
width
,
unsigned
height
)
{
rectangle
rect
;
//int tempX, tempY; //stores the information of the column and row curently beeing evalueted
Bool
foundColor
=
False
;
int
count
=
0
;
uint32_t
extractedColor
;
for
(
int
pixY
=
0
;
pixY
<
height
;
pixY
++
)
{
for
(
int
pixX
=
0
;
pixX
<
width
;
pixX
++
)
{
if
(
color
==
image
->
f
.
get_pixel
(
image
,
pixX
,
pixY
))
{
extractedColor
=
(
unsigned
char
)
image
->
data
[
count
];
extractedColor
+=
(
unsigned
char
)
image
->
data
[
count
+
1
]
*
256
;
extractedColor
+=
(
unsigned
char
)
image
->
data
[
count
+
2
]
*
256
*
256
;
if
(
debug
)
{
//printf("%06" PRIx32 "\n", extractedColor);
//printf("DEBUG: extracted color is %06" PRIx32 " and given color is %06" PRIx32 "\n", extractedColor, color);
}
if
(
color
==
extractedColor
)
{
if
(
foundColor
)
{
if
(
rect
.
y
==
pixY
)
{
rect
.
width
+=
1
;
...
...
@@ -223,15 +353,18 @@ rectangle searchForColorRect (unsigned long color, XImage *image, unsigned width
}
}
}
count
+=
4
;
}
}
if
(
debug
)
{
if
(
foundColor
)
{
printf
(
"
%lx
found at x %d y %d
\n
"
,
color
,
rect
.
x
,
rect
.
y
);
printf
(
"with a width of %d and a height of %d
\n
"
,
rect
.
width
,
rect
.
height
);
printf
(
"
DEBUG: %06"
PRIx32
"
found at x %d y %d
\n
"
,
color
,
rect
.
x
,
rect
.
y
);
printf
(
"
DEBUG:
with a width of %d and a height of %d
\n
"
,
rect
.
width
,
rect
.
height
);
}
//printf("DEBUG: extracted color is %06" PRIx32 " and given color is %06" PRIx32 "\n", extractedColor, color);
}
if
(
foundColor
)
{
printf
(
"%d %d %d %d
\n
"
,
rect
.
x
,
rect
.
y
,
rect
.
width
,
rect
.
height
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment