Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 8
UseTab: Never
...

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
build/
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ project(cpp-opencv-example-1)

add_executable(main main.cpp)


find_package(OpenCV REQUIRED)
target_include_directories(main PRIVATE ${OpenCV_INCLUDE_DIRS})
target_link_libraries(main PRIVATE ${OpenCV_LIBS})

find_package(LibLZMA REQUIRED)
target_include_directories(main PRIVATE ${LIBLZMA_INCLUDE_DIRS})
target_link_libraries(main PRIVATE ${LIBLZMA_LIBRARIES})
target_link_libraries(main PRIVATE ${LIBLZMA_LIBRARIES})

add_subdirectory(lib/binops)
target_link_libraries(main PRIVATE binops)
15 changes: 0 additions & 15 deletions helper_functions.h

This file was deleted.

Binary file added image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions lib/binops/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include(GoogleTest)
add_executable(runtests test/main test/addition_tests.cpp)
find_package(GTest REQUIRED)
target_link_libraries(runtests PRIVATE GTest::GTest GTest::Main binops)
gtest_discover_tests(runtests)

add_library(binops SHARED include/binops.hpp src/addition.cpp)
set_target_properties(binops PROPERTIES PUBLIC_HEADER include/binops.hpp)
23 changes: 23 additions & 0 deletions lib/binops/include/binops.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef binops_hpp
#define binops_hpp

#include <stdio.h>

namespace BinOps {
class Addition {
public:
void setLHS(int lhs);
void setRHS(int rhs);

int getLHS();
int getRHS();

int perform();

private:
int lhs;
int rhs;
};
} // namespace BinOps

#endif
13 changes: 13 additions & 0 deletions lib/binops/src/addition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "../include/binops.hpp"

using namespace BinOps;

void Addition::setLHS(int lhs) { this->lhs = lhs; }

void Addition::setRHS(int rhs) { this->rhs = rhs; }

int Addition::getLHS() { return this->lhs; }

int Addition::getRHS() { return this->rhs; }

int Addition::perform() { return this->lhs + this->rhs; }
61 changes: 61 additions & 0 deletions lib/binops/test/addition_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <gtest/gtest.h>
#include <stdio.h>
#include "../include/binops.hpp"

using namespace BinOps;

TEST(AdditionTests, TestItIsNotNil) {
// when
Addition a = Addition();

// then
ASSERT_NE(&a, nullptr);
}

TEST(AdditionTests, TestItSetsTheLHS) {
// given
Addition a = Addition();

// when
a.setLHS(3);

// then
ASSERT_EQ(a.getLHS(), 3);
}

TEST(AdditionTests, TestItSetsTheRHS) {
// given
Addition a = Addition();

// when
a.setRHS(100);

// then
ASSERT_EQ(a.getRHS(), 100);
}

TEST(AdditionTests, TestItGivesTheExpectedResultFor3And5) {
// given
Addition a = Addition();
a.setLHS(3);
a.setRHS(5);

// when
int result = a.perform();

// then
ASSERT_EQ(result, 8);
}

TEST(AdditionTests, TestItGivesTheExpectedResultFor1And2) {
// given
Addition a = Addition();
a.setLHS(1);
a.setRHS(2);

// when
int result = a.perform();

// then
ASSERT_EQ(result, 3);
}
7 changes: 7 additions & 0 deletions lib/binops/test/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <gtest/gtest.h>
#include <stdio.h>

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
86 changes: 44 additions & 42 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "helper_functions.h"
#include <iostream>
#include "lib/binops/include/binops.hpp"

using namespace cv;
using namespace std;

int main(int argc, const char * argv[]) {
if (argc !=2) {
cout << "Usage wrong" << endl;
return -1;
}

Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);

if(! image.data )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}

namedWindow( "Display window", WINDOW_AUTOSIZE );
imshow( "Display window", image );

waitKey(0);

Mat image_bw;
cvtColor(image, image_bw, COLOR_RGB2GRAY);

namedWindow( "Display window - b&w", WINDOW_AUTOSIZE );
imshow( "Display window - b&w", image_bw);

waitKey(0);

Mat image_bin;
threshold(image_bw, image_bin, 125, 255, THRESH_BINARY);

namedWindow( "Display window - bin", WINDOW_AUTOSIZE );
imshow( "Display window - bin", image_bin);

waitKey(0);

int aux = rgb2gray(4, 4);

std::cout << "Hello, Lena!\n" << aux << endl;
return 0;
int main(int argc, const char* argv[]) {
if (argc != 2) {
cout << "Usage wrong" << endl;
return -1;
}

Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);

if (!image.data) {
cout << "Could not open or find the image" << std::endl;
return -1;
}

namedWindow("Display window", WINDOW_AUTOSIZE);
imshow("Display window", image);

waitKey(0);

Mat image_bw;
cvtColor(image, image_bw, COLOR_RGB2GRAY);

namedWindow("Display window - b&w", WINDOW_AUTOSIZE);
imshow("Display window - b&w", image_bw);

waitKey(0);

Mat image_bin;
threshold(image_bw, image_bin, 125, 255, THRESH_BINARY);

namedWindow("Display window - bin", WINDOW_AUTOSIZE);
imshow("Display window - bin", image_bin);

waitKey(0);

BinOps::Addition a = BinOps::Addition();
a.setLHS(4);
a.setRHS(4);
int result = a.perform();

std::cout << "Hello, Lena!\n" << result << endl;
return 0;
}