Added C binding to main library

This commit is contained in:
Matt Hill
2017-05-07 08:47:16 -04:00
parent fa561a063a
commit ae9cb42102
7 changed files with 2 additions and 110 deletions

View File

@@ -1,3 +1,4 @@
usr/include/alpr.h
usr/include/alpr_c.h
usr/lib/lib*.a
usr/lib/lib*so

View File

@@ -47,9 +47,6 @@ if ( NOT DEFINED WITH_BINDING_JAVA )
SET(WITH_BINDING_JAVA ON)
ENDIF()
if ( NOT DEFINED WITH_BINDING_C )
SET(WITH_BINDING_C ON)
ENDIF()
if ( NOT DEFINED WITH_BINDING_PYTHON )
SET(WITH_BINDING_PYTHON ON)
@@ -209,9 +206,6 @@ if (WITH_BINDING_PYTHON)
add_subdirectory(bindings/python)
ENDIF()
if (WITH_BINDING_C)
add_subdirectory(bindings/c)
ENDIF()
if (WITH_BINDING_GO)
set(OPENALPR_LIB_GO openalprgo)

View File

@@ -1,24 +0,0 @@
cmake_minimum_required (VERSION 2.6)
include_directories(../../openalpr/)
set(alprc_source
alpr_c.cpp
)
add_library(openalprc SHARED ${alprc_source})
set_target_properties(openalprc PROPERTIES SOVERSION ${OPENALPR_MAJOR_VERSION})
TARGET_LINK_LIBRARIES(openalprc openalpr)
add_executable(alprc_test alprc_test.c)
TARGET_LINK_LIBRARIES(alprc_test openalprc)
install (TARGETS openalprc DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install (FILES alpr_c.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include)

View File

@@ -1,80 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: alprc_test.c
* Author: mhill
*
* Created on October 16, 2016, 11:09 AM
*/
#include <stdio.h>
#include <stdlib.h>
#include "alpr_c.h"
void ReadFile(const char *name, char** buffer, size_t* size)
{
FILE *file;
//Open file
file = fopen(name, "rb");
if (!file)
{
fprintf(stderr, "Unable to open file %s", name);
return;
}
//Get file length
fseek(file, 0, SEEK_END);
*size=ftell(file);
fseek(file, 0, SEEK_SET);
//Allocate memory
*buffer=(char *)malloc(*size+1);
if (!(*buffer))
{
fprintf(stderr, "Memory error!");
fclose(file);
return;
}
//Read file contents into buffer
fread(*buffer, *size, 1, file);
fclose(file);
}
/*
*
*/
int main(int argc, char** argv) {
OPENALPR* openalpr = openalpr_init("us", "/etc/openalpr/openalpr.conf", "/usr/share/openalpr/runtime_data/");
const char* IMAGE_FILE="/storage/projects/alpr/samples/testing/car1.jpg";
size_t size;
char* buffer;
printf("Loading image: %s\n", IMAGE_FILE);
ReadFile(IMAGE_FILE, &buffer, &size);
struct AlprCRegionOfInterest roi;
roi.x = 0;
roi.y = 0;
roi.width = 1024;
roi.height = 768;
printf("Recognizing plates\n");
printf("Image size: %lu\n", (long) size);
char* plate_json = openalpr_recognize_encodedimage(openalpr, buffer, size, roi);
printf("results:\n%s\n", plate_json);
free(plate_json);
free(buffer);
openalpr_cleanup(openalpr);
return (EXIT_SUCCESS);
}

View File

@@ -4,6 +4,7 @@
set(lpr_source_files
alpr.cpp
alpr_impl.cpp
alpr_c.cpp
config.cpp
config_helper.cpp
detection/detector.cpp