|
|
//
|
|
|
// Created by Arnaud Blanchard on 22/12/15.
|
|
|
// Copyright ETIS 2015. All rights reserved.
|
|
|
//
|
|
|
#include "blc_channel.h"
|
|
|
#include "blc_program.h"
|
|
|
#include <unistd.h>
|
|
|
#include <math.h>
|
|
|
|
|
|
#define DEFAULT_OUTPUT_NAME ":point_of_interest<pid>"
|
|
|
|
|
|
#define GRAD(x,y) grad.uchars[(x)+(y)*grad_width]
|
|
|
|
|
|
/** See how to use Filter of Scharr
|
|
|
*
|
|
|
* -3 0 3
|
|
|
* -10 0 10
|
|
|
* -3 0 3 / 32
|
|
|
*
|
|
|
*/
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv){
|
|
|
blc_channel input, output, grad;
|
|
|
char const *output_name, *input_name;
|
|
|
int out_width, out_height, in_width, in_height, grad_height, grad_width;
|
|
|
int i, j, sobel;
|
|
|
|
|
|
blc_program_set_description("Find a points of interest on a image");
|
|
|
blc_program_add_option(&output_name, 'o', "output", "blc_channel-out", "channel name", DEFAULT_OUTPUT_NAME);
|
|
|
blc_program_add_parameter(&input_name, "blc_channel-in", 1, "image from where you want to find the points of interest", NULL);
|
|
|
blc_program_init(&argc, &argv, blc_quit);
|
|
|
|
|
|
if (strcmp(output_name, DEFAULT_OUTPUT_NAME)==0) SYSTEM_ERROR_CHECK(asprintf((char**)&output_name,":point_of_interest%d", getpid()), -1, NULL);
|
|
|
|
|
|
input.open(input_name, BLC_CHANNEL_READ);
|
|
|
blc_loop_try_add_waiting_semaphore(input.sem_new_data);
|
|
|
blc_loop_try_add_posting_semaphore(input.sem_ack_data);
|
|
|
|
|
|
in_width=input.dims[0].length;
|
|
|
in_height=input.dims[1].length;
|
|
|
|
|
|
grad_width=in_width-1;
|
|
|
grad_height=in_height-1;
|
|
|
|
|
|
grad.init('UIN8', 'NDEF',2, grad_width, grad_height);
|
|
|
|
|
|
out_width=grad_width-1;
|
|
|
out_height=grad_height-1;
|
|
|
|
|
|
output.create_or_open(output_name, BLC_CHANNEL_WRITE, input.type, 'Y800', 2, out_width, out_height);
|
|
|
output.publish();
|
|
|
|
|
|
blc_loop_try_add_waiting_semaphore(output.sem_ack_data);
|
|
|
blc_loop_try_add_posting_semaphore(output.sem_new_data);
|
|
|
|
|
|
BLC_COMMAND_LOOP(0){
|
|
|
FOR(j, grad_height){
|
|
|
FOR(i, grad_width){
|
|
|
grad.uchars[i+j*grad_width]=(abs(input.uchars[i+j*in_width]-input.uchars[i+j*in_width+1])+abs(input.uchars[i+j*in_width]-input.uchars[i+(j+1)*in_width]))/2;
|
|
|
}
|
|
|
}
|
|
|
FOR(j, out_height){
|
|
|
FOR(i, out_width){
|
|
|
sobel=-GRAD(i, j)-GRAD(i+1, j)-GRAD(i+2, j)\
|
|
|
-GRAD(i, j+1)+8*GRAD(i+1, j+1)-GRAD(i+2, j+1)\
|
|
|
-GRAD(i, j+2)-GRAD(i+1, j+2)- GRAD(i+2, j+2);
|
|
|
|
|
|
output.uchars[i+j*out_width]=(sobel > 0 && GRAD(i+1, j+1)>10) ? 255 : 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
} |
...
|
...
|
|