Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
camtron
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kr69sugu
camtron
Commits
0b5a9d7f
Commit
0b5a9d7f
authored
5 years ago
by
Thomas Boy
Browse files
Options
Downloads
Patches
Plain Diff
intergrated the libarchive reading function to read a tar which uses the bgs algos
parent
bdfc8712
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CMakeLists.txt
+1
-1
1 addition, 1 deletion
CMakeLists.txt
Demo.cpp
+361
-389
361 additions, 389 deletions
Demo.cpp
Demo2.cpp
+104
-94
104 additions, 94 deletions
Demo2.cpp
with
466 additions
and
484 deletions
CMakeLists.txt
+
1
−
1
View file @
0b5a9d7f
...
...
@@ -138,7 +138,7 @@ target_link_libraries(bgslibrary ${OpenCV_LIBS} libbgs)
# set_target_properties(bgslibrary PROPERTIES OUTPUT_NAME bgs)
add_executable
(
bgs_demo
${
demo
}
)
target_link_libraries
(
bgs_demo
${
OpenCV_LIBS
}
libbgs
)
target_link_libraries
(
bgs_demo
${
OpenCV_LIBS
}
${
LibArchive_LIBRARIES
}
libbgs
)
add_executable
(
bgs_demo2
${
demo2
}
)
target_link_libraries
(
bgs_demo2
${
OpenCV_LIBS
}
${
LibArchive_LIBRARIES
}
libbgs
)
...
...
This diff is collapsed.
Click to expand it.
Demo.cpp
+
361
−
389
View file @
0b5a9d7f
This diff is collapsed.
Click to expand it.
Demo2.cpp
+
104
−
94
View file @
0b5a9d7f
...
...
@@ -52,12 +52,12 @@ bool cmdOptionExists(char** begin, char** end, const std::string& option)
}
static
std
::
vector
<
char
>
copy
_d
ata
(
struct
archive
*
aw
,
unsigned
char
*
buffer
);
static
std
::
vector
<
char
>
copy
D
ata
InBuffer
(
struct
archive
*
aw
);
static
void
errmsg
(
const
char
*
);
static
void
fail
(
const
char
*
,
const
char
*
,
int
);
static
void
msg
(
const
char
*
);
static
void
warn
(
const
char
*
,
const
char
*
);
//
static void errmsg(const char *);
//
static void fail(const char *, const char *, int);
//
static void msg(const char *);
//
static void warn(const char *, const char *);
...
...
@@ -110,45 +110,47 @@ int main(int argc, char * argv[])
outputDir
=
string
(
testOutputDir
);
}
struct
archive
*
a
;
struct
archive
*
a
rchive
;
struct
archive
*
ext
;
struct
archive_entry
*
entry
;
int
r
;
int
flags
=
ARCHIVE_EXTRACT_TIME
;
// see https://linux.die.net/man/3/archive_write_disk for more flags
const
char
*
filename
=
"data_sized.tar"
;
a
=
archive_read_new
();
a
rchive
=
archive_read_new
();
ext
=
archive_write_disk_new
();
archive_write_disk_set_options
(
ext
,
flags
);
/*
* Note: archive_write_disk_set_standard_lookup() is useful
* here, but it requires library routines that can add 500k or
* more to a static executable.
*/
archive_read_support_format_tar
(
a
);
/*
* On my system, enabling other archive formats adds 20k-30k
* each. Enabling gzip decompression adds about 20k.
* Enabling bzip2 is more expensive because the libbz2 library
* isn't very well factored.
*/
archive_read_support_format_tar
(
archive
);
//we get the filename
if
(
filename
!=
NULL
&&
strcmp
(
filename
,
"-"
)
==
0
)
filename
=
NULL
;
if
((
r
=
archive_read_open_filename
(
a
,
filename
,
10240
)))
fail
(
"archive_read_open_filename()"
,
archive_error_string
(
a
),
r
);
//and open the handler
if
((
r
=
archive_read_open_filename
(
archive
,
filename
,
10240
)))
{
cerr
<<
"archive_read_open_filename: error: "
<<
archive_error_string
(
archive
)
<<
" will abort"
<<
endl
;
exit
(
1
);
// fail("archive_read_open_filename()",
// archive_error_string(a), r);
}
int
counter
=
0
;
for
(;;)
{
r
=
archive_read_next_header
(
a
,
&
entry
);
r
=
archive_read_next_header
(
a
rchive
,
&
entry
);
if
(
r
==
ARCHIVE_EOF
)
break
;
if
(
r
!=
ARCHIVE_OK
)
fail
(
"archive_read_next_header()"
,
archive_error_string
(
a
),
1
);
msg
(
"x "
);
{
cerr
<<
"archive_read_next_header: error: "
<<
archive_error_string
(
archive
)
<<
" will abort"
<<
endl
;
exit
(
1
);
// fail("archive_read_next_header()",
// archive_error_string(a), 1);
}
//msg("x ");
///char *buffer = malloc (sizeof(char) * 400000);
Mat
img
=
Mat
::
zeros
(
1936
,
1456
,
CV_8UC3
);
//
Mat img =Mat::zeros(1936,1456,CV_8UC3);
//new way
//std::ifstream file("img.jpg");
...
...
@@ -157,39 +159,53 @@ int main(int argc, char * argv[])
// file >> std::noskipws;
// std::copy(std::istream_iterator<char>(file), std::istream_iterator<char>(), std::back_inserter(data));
const
char
*
fileNamePtr
=
archive_entry_pathname
(
entry
);
std
::
string
filename
(
fileNamePtr
,
strlen
(
fileNamePtr
)
);
cout
<<
"fileName: "
<<
filename
<<
endl
;
//TODO we should test what file we have, this filenumber n = n - 1 ??
msg
(
archive_entry_pathname
(
entry
));
//msg(archive_entry_pathname(entry));
r
=
archive_write_header
(
ext
,
entry
);
if
(
r
!=
ARCHIVE_OK
)
{
cerr
<<
"archive_write_header() error: "
<<
archive_error_string
(
ext
)
<<
endl
;
}
else
{
r
=
archive_write_header
(
ext
,
entry
);
vec
=
copyDataInBuffer
(
archive
);
//no // we cast the data pointer to void, because we know what we do ??
if
(
vec
.
empty
())
cerr
<<
"error during load data into buffer"
;
r
=
archive_write_finish_entry
(
ext
);
if
(
r
!=
ARCHIVE_OK
)
warn
(
"archive_write_header()"
,
archive_error_string
(
ext
));
else
{
vec
=
copy_data
(
a
,
img
.
data
);
//no // we cast the data pointer to void, because we know what we do ??
r
=
archive_write_finish_entry
(
ext
);
if
(
r
!=
ARCHIVE_OK
)
fail
(
"archive_write_finish_entry()"
,
archive_error_string
(
ext
),
1
);
}
cerr
<<
"archive_write_finish_entry: error: "
<<
archive_error_string
(
ext
)
<<
" will abort"
<<
endl
;
exit
(
1
);
// fail("archive_write_finish_entry()",
// archive_error_string(ext), 1);
}
}
msg
(
"
\n
"
);
//we read the image buffer as a jpg picture and decode it
Mat
img2
=
imdecode
(
Mat
(
vec
),
1
);
// //here we could use our image
// //we show what we got
// namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
// imshow( "Display window", img2 ); // Show our image inside it.
// cv::imwrite("foo.jpg", img2);
// //msg("\n");
if
(
counter
>
10
)
exit
(
1
);
counter
++
;
Mat
img2
=
imdecode
(
Mat
(
vec
),
1
);
//
waitKey(0
);
//we show what we got
namedWindow
(
"Display window"
,
WINDOW_AUTOSIZE
);
// Create a window for display.
imshow
(
"Display window"
,
img2
);
// Show our image inside it.
cv
::
imwrite
(
"foo.jpg"
,
img2
);
waitKey
(
0
);
}
archive_read_close
(
a
);
archive_read_free
(
a
);
archive_read_close
(
a
rchive
);
archive_read_free
(
a
rchive
);
archive_write_close
(
ext
);
archive_write_free
(
ext
);
...
...
@@ -197,7 +213,7 @@ int main(int argc, char * argv[])
return
0
;
}
static
std
::
vector
<
char
>
copy
_d
ata
(
struct
archive
*
aw
,
unsigned
char
*
buffer
)
static
std
::
vector
<
char
>
copy
D
ata
InBuffer
(
struct
archive
*
aw
)
{
int
r
;
const
void
*
buff
;
...
...
@@ -208,19 +224,19 @@ static std::vector<char> copy_data(struct archive *aw, unsigned char *buffer)
#else
off_t
offset
;
#endif
unsigned
int
myOffsetCounter
=
0
;
int
counterIteration
=
0
;
//
unsigned int myOffsetCounter = 0;
//
int counterIteration = 0;
ofstream
myfile
;
myfile
.
open
(
"tmpPicture.jpg"
,
ios
::
out
|
ios
::
binary
);
if
(
!
myfile
.
is_open
())
return
vec
;
//
ofstream myfile;
//
myfile.open ("tmpPicture.jpg", ios::out | ios::binary);
//
if (!myfile.is_open())
//
return vec;
for
(;;)
{
r
=
archive_read_data_block
(
aw
,
&
buff
,
&
size
,
&
offset
);
if
(
r
==
ARCHIVE_EOF
)
{
return
vec
;
// everything fine
return
vec
;
// everything fine
, were are just at the end
}
if
(
r
!=
ARCHIVE_OK
)
...
...
@@ -230,64 +246,58 @@ static std::vector<char> copy_data(struct archive *aw, unsigned char *buffer)
}
//r = archive_write_data_block(aw, buff, size, offset);
//we mem copy the buffer
cout
<<
counterIteration
++<<
" offset: "
<<
offset
<<
" size: "
<<
size
<<
endl
;
//
cout <<counterIteration++<< " offset: "<< offset<< " size: "<< size<<endl;
//memcpy( &buffer[myOffsetCounter], (char*) buff, size * sizeof( char ) );
//we simply copy it to the end
//std::copy ( buff, buff+size, vec.end() );
myOffsetCounter
+=
size
;
//
myOffsetCounter += size;
//a good discussion : https://stackoverflow.com/questions/259297/how-do-you-copy-the-contents-of-an-array-to-a-stdvector-in-c-without-looping
// // Method 2: Same as 1 but pre-extend the vector by the size of the array using reserve
// {
// vec.reserve(vec.size() + size);
// std::copy((char*) &buff[0],(char*) &buff[size], back_inserter(vec));
// }
// Method 4: vector::insert
{
//we rename our pointer
//we rename our pointer
to avoid a weird compiler warning
char
*
foo
=
(
char
*
)
buff
;
vec
.
insert
(
vec
.
end
(),
&
foo
[
0
],
&
foo
[
size
]);
}
myfile
.
write
((
char
*
)
buff
,
size
);
//
myfile.write ((char*)buff,size);
// if (r != ARCHIVE_OK) {
// warn("archive_write_data_block()",
// archive_error_string(aw));
// return (r);
// }
}
myfile
.
close
();
//
myfile.close();
return
vec
;
}
static
void
msg
(
const
char
*
m
)
{
write
(
1
,
m
,
strlen
(
m
));
}
static
void
errmsg
(
const
char
*
m
)
{
write
(
2
,
m
,
strlen
(
m
));
}
static
void
warn
(
const
char
*
f
,
const
char
*
m
)
{
errmsg
(
f
);
errmsg
(
" failed: "
);
errmsg
(
m
);
errmsg
(
"
\n
"
);
}
static
void
fail
(
const
char
*
f
,
const
char
*
m
,
int
r
)
{
warn
(
f
,
m
);
exit
(
r
);
}
//
static void
//
msg(const char *m)
//
{
//
write(1, m, strlen(m));
//
}
//
static void
//
errmsg(const char *m)
//
{
//
write(2, m, strlen(m));
//
}
//
static void
//
warn(const char *f, const char *m)
//
{
//
errmsg(f);
//
errmsg(" failed: ");
//
errmsg(m);
//
errmsg("\n");
//
}
//
static void
//
fail(const char *f, const char *m, int r)
//
{
//
warn(f, m);
//
exit(r);
//
}
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