mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
Add check size and format func in PikaCV
This commit is contained in:
parent
b794fb3d11
commit
121ad21697
@ -108,7 +108,14 @@ class Converter(TinyObj):
|
||||
@staticmethod
|
||||
def toBGR888(image: Image):
|
||||
"""Convert the image to BGR888"""
|
||||
|
||||
def converter(image:Image,format:int):
|
||||
"""
|
||||
2:RGB888
|
||||
3:BGR888
|
||||
4:RGB565
|
||||
5:GRAY
|
||||
6:BMP
|
||||
"""
|
||||
|
||||
class Transforms(TinyObj):
|
||||
"""The transforms class is used to
|
||||
|
@ -419,3 +419,28 @@ void PikaCV_Converter_toBGR888(PikaObj* self, PikaObj* image) {
|
||||
img->size = size_new;
|
||||
arg_deinit(arg_data_new);
|
||||
}
|
||||
|
||||
void PikaCV_Converter_converter(PikaObj *self, int format, PikaObj* image){
|
||||
switch (format)
|
||||
{
|
||||
case PikaCV_ImageFormat_Type_RGB888:
|
||||
PikaCV_Converter_toRGB888(self,image);
|
||||
break;
|
||||
case PikaCV_ImageFormat_Type_BGR888:
|
||||
PikaCV_Converter_toBGR888(self,image);
|
||||
break;
|
||||
case PikaCV_ImageFormat_Type_RGB565:
|
||||
PikaCV_Converter_toRGB565(self,image);
|
||||
break;
|
||||
case PikaCV_ImageFormat_Type_GRAY:
|
||||
PikaCV_Converter_toGray(self,image);
|
||||
break;
|
||||
case PikaCV_ImageFormat_Type_BMP:
|
||||
PikaCV_Converter_toBMP(self,image);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
@ -10,7 +10,7 @@ void PikaCV_Image___init__(PikaObj* self) {
|
||||
}
|
||||
/* init */
|
||||
PikaCV_Image image = {
|
||||
.format = PikaCV_ImageFormat_Type_Unknown,
|
||||
.format = PikaCV_ImageFormat_Type_Empty,
|
||||
.width = 0,
|
||||
.height = 0,
|
||||
.size = 0,
|
||||
@ -56,7 +56,7 @@ Arg* PikaCV_Image_data(PikaObj* self) {
|
||||
int PikaCV_Image_format(PikaObj* self) {
|
||||
PikaCV_Image* image = obj_getStruct(self, "image");
|
||||
if (NULL == image) {
|
||||
return PikaCV_ImageFormat_Type_Unknown;
|
||||
return PikaCV_ImageFormat_Type_Empty;
|
||||
}
|
||||
return image->format;
|
||||
}
|
||||
@ -232,15 +232,15 @@ void PikaCV_Image_add(PikaObj* self, PikaObj* image) {
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (img->format != src->format) {
|
||||
if(!PikaCV_Format_CheckTwo(self,image,PikaCV_Check_ReturnError)){
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("unsupported image format\n");
|
||||
return;
|
||||
}
|
||||
if (img->size != src->size) {
|
||||
if(!PikaCV_Size_Check(self,image,PikaCV_Check_SHW)){
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("illegal image size\n");
|
||||
return;
|
||||
__platform_printf("illegal image size\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
uint8_t* src_data = _image_getData(self);
|
||||
@ -276,15 +276,15 @@ void PikaCV_Image_minus(PikaObj* self, PikaObj* image) {
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (img->format != src->format) {
|
||||
if(!PikaCV_Format_CheckTwo(self,image,PikaCV_Check_ReturnError)){
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("unsupported image format\n");
|
||||
return;
|
||||
}
|
||||
if (img->size != src->size) {
|
||||
if(!PikaCV_Size_Check(self,image,PikaCV_Check_SHW)){
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("illegal image size\n");
|
||||
return;
|
||||
__platform_printf("illegal image size\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
uint8_t* src_data = _image_getData(self);
|
||||
@ -324,20 +324,20 @@ void PikaCV_Image_merge(PikaObj* self, PikaObj* B, PikaObj* G, PikaObj* R) {
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (PikaCV_ImageFormat_Type_RGB888 != src->format) {
|
||||
if (!PikaCV_Format_Check(self,PikaCV_ImageFormat_Type_RGB888,PikaCV_Check_ReturnError)) {
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("unsupported image format\n");
|
||||
return;
|
||||
}
|
||||
if (PikaCV_ImageFormat_Type_GRAY != Channel_B->format ||
|
||||
PikaCV_ImageFormat_Type_GRAY != Channel_G->format ||
|
||||
PikaCV_ImageFormat_Type_GRAY != Channel_R->format) {
|
||||
if (!PikaCV_Format_Check(B,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_ReturnError) ||
|
||||
!PikaCV_Format_Check(G,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_ReturnError) ||
|
||||
!PikaCV_Format_Check(R,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_ReturnError)) {
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("unsupported image format\n");
|
||||
return;
|
||||
}
|
||||
if (Channel_B->size != Channel_G->size ||
|
||||
Channel_B->size != Channel_R->size) {
|
||||
if (!PikaCV_Size_Check(B,G,PikaCV_Check_SHW) ||
|
||||
!PikaCV_Size_Check(B,R,PikaCV_Check_SHW)) {
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("illegal image size\n");
|
||||
return;
|
||||
@ -371,7 +371,7 @@ PikaObj* PikaCV_Image_split(PikaObj* self) {
|
||||
pika_assert(0);
|
||||
return NULL;
|
||||
}
|
||||
if (PikaCV_ImageFormat_Type_RGB888 != src->format) {
|
||||
if(!PikaCV_Format_Check(self,PikaCV_ImageFormat_Type_RGB888,PikaCV_Check_ReturnError)){
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("unsupported image format\n");
|
||||
return NULL;
|
||||
|
@ -48,10 +48,7 @@ void PikaCV_Transforms_threshold(PikaObj* self,
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (src->format != PikaCV_ImageFormat_Type_GRAY) {
|
||||
PikaCV_Converter_toGray(self, image);
|
||||
}
|
||||
|
||||
PikaCV_Format_Check(image,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_Converter);
|
||||
uint8_t* src_data = _image_getData(image);
|
||||
|
||||
int i;
|
||||
@ -99,9 +96,7 @@ void PikaCV_Transforms_setROI(PikaObj* self,
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (src->format != PikaCV_ImageFormat_Type_RGB888) {
|
||||
PikaCV_Converter_toRGB888(self, image);
|
||||
}
|
||||
PikaCV_Format_Check(image,PikaCV_ImageFormat_Type_RGB888,PikaCV_Check_Converter);
|
||||
if (x <= 0 || y <= 0 || w <= 0 || h <= 0) {
|
||||
pika_assert(0);
|
||||
return;
|
||||
@ -141,9 +136,7 @@ int PikaCV_Transforms_getOTSUthre(PikaObj* self, PikaObj* image) {
|
||||
pika_assert(0);
|
||||
return 0;
|
||||
}
|
||||
if (src->format != PikaCV_ImageFormat_Type_GRAY) {
|
||||
PikaCV_Converter_toGray(self, image);
|
||||
}
|
||||
PikaCV_Format_Check(image,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_Converter);
|
||||
const int Grayscale = 256;
|
||||
int width = src->width;
|
||||
int height = src->height;
|
||||
@ -190,10 +183,7 @@ void PikaCV_Transforms_setOTSU(PikaObj* self, PikaObj* image) {
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (src->format != PikaCV_ImageFormat_Type_GRAY) {
|
||||
PikaCV_Converter_toGray(self, image);
|
||||
}
|
||||
|
||||
PikaCV_Format_Check(image,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_Converter);
|
||||
int thre = PikaCV_Transforms_getOTSUthre(self, image);
|
||||
uint8_t* src_data = _image_getData(image);
|
||||
|
||||
@ -224,9 +214,7 @@ void PikaCV_Transforms_resize(PikaObj* self,
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (src->format != PikaCV_ImageFormat_Type_RGB888) {
|
||||
PikaCV_Converter_toRGB888(self, image);
|
||||
}
|
||||
PikaCV_Format_Check(image,PikaCV_ImageFormat_Type_RGB888,PikaCV_Check_Converter);
|
||||
|
||||
int size_new = x * y * 3;
|
||||
Arg* arg_data_new = arg_setBytes(NULL, "", NULL, size_new);
|
||||
@ -278,10 +266,7 @@ void PikaCV_Transforms_adaptiveThreshold(PikaObj* self,
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (src->format != PikaCV_ImageFormat_Type_GRAY) {
|
||||
PikaCV_Converter_toGray(self, image);
|
||||
}
|
||||
|
||||
PikaCV_Format_Check(image,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_Converter);
|
||||
int size = src->size;
|
||||
uint8_t* src_data = _image_getData(image);
|
||||
uint8_t* src_copy;
|
||||
|
107
package/PikaCV/PikaCV_common.c
Normal file
107
package/PikaCV/PikaCV_common.c
Normal file
@ -0,0 +1,107 @@
|
||||
#include "PikaCV_common.h"
|
||||
#include "PikaCV_Converter.h"
|
||||
|
||||
int PikaCV_Format_Check(PikaObj* image,PikaCV_ImageFormat_Type type,PikaCV_Check_ReturnMode returnMode){
|
||||
// return mode: 0
|
||||
// 1
|
||||
// 2
|
||||
//PikaObj* self;
|
||||
|
||||
PikaCV_Image* src = obj_getStruct(image, "image");
|
||||
switch (returnMode)
|
||||
{
|
||||
case PikaCV_Check_ReturnError:
|
||||
if(src->format != type){
|
||||
//obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case PikaCV_Check_Converter:
|
||||
/* code */
|
||||
if(src->format != type){
|
||||
PikaCV_Converter_converter((PikaObj*)NULL,type,image);
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int PikaCV_Format_CheckTwo(PikaObj* image1,PikaObj* image2,PikaCV_Check_ReturnMode returnMode){
|
||||
//PikaObj* self;
|
||||
|
||||
PikaCV_Image* src1 = obj_getStruct(image1, "image");
|
||||
PikaCV_Image* src2 = obj_getStruct(image2, "image");
|
||||
|
||||
switch (returnMode)
|
||||
{
|
||||
case PikaCV_Check_ReturnError:
|
||||
if(src1->format != src2->format){
|
||||
//obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case PikaCV_Check_Converter:
|
||||
/* code */
|
||||
if(src1->format != src2->format){
|
||||
PikaCV_Converter_converter((PikaObj*)NULL,src1->format,image2);
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PikaCV_Size_Check(PikaObj* image1,PikaObj* image2,PikaCV_Check_SizeMode sizeMode){
|
||||
//sPikaObj* self;
|
||||
|
||||
PikaCV_Image* src1 = obj_getStruct(image1, "image");
|
||||
PikaCV_Image* src2 = obj_getStruct(image2, "image");
|
||||
|
||||
switch (sizeMode)
|
||||
{
|
||||
case PikaCV_Check_Size:
|
||||
/* code */
|
||||
if(src1->size != src2->size){
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case PikaCV_Check_SHW:
|
||||
/* code */
|
||||
if(src1->size != src2->size || src1->height!= src2->height || src1->width != src2->width){
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case PikaCV_Check_HW:
|
||||
/* code */
|
||||
if(src1->height!= src2->height || src1->width != src2->width){
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
#include "./3rd-party/tjpgd/src/tjpgd.h"
|
||||
#include "PikaObj.h"
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
typedef enum PikaCV_ImageFormat_Type {
|
||||
PikaCV_ImageFormat_Type_Unknown = 0,
|
||||
PikaCV_ImageFormat_Type_Empty = 0,
|
||||
PikaCV_ImageFormat_Type_JPEG,
|
||||
PikaCV_ImageFormat_Type_RGB888,
|
||||
PikaCV_ImageFormat_Type_BGR888,
|
||||
@ -18,6 +19,21 @@ typedef struct PikaCV_Image {
|
||||
int size;
|
||||
} PikaCV_Image;
|
||||
|
||||
typedef enum {
|
||||
PikaCV_Check_ReturnError = 0,
|
||||
PikaCV_Check_Converter,
|
||||
} PikaCV_Check_ReturnMode;
|
||||
|
||||
typedef enum {
|
||||
PikaCV_Check_Size = 0,
|
||||
PikaCV_Check_SHW,
|
||||
PikaCV_Check_HW,
|
||||
} PikaCV_Check_SizeMode;
|
||||
|
||||
uint8_t* _image_getData(PikaObj* self);
|
||||
PIKA_RES _image_setData(PikaObj* self, uint8_t* data, int size);
|
||||
int _image_getDataSize(PikaObj* self);
|
||||
int _image_getDataSize(PikaObj* self);
|
||||
|
||||
int PikaCV_Format_Check(PikaObj* image,PikaCV_ImageFormat_Type type,PikaCV_Check_ReturnMode returnMode);
|
||||
int PikaCV_Format_CheckTwo(PikaObj* image1,PikaObj* image2,PikaCV_Check_ReturnMode returnMode);
|
||||
int PikaCV_Size_Check(PikaObj* image1,PikaObj* image2,PikaCV_Check_SizeMode sizeMode);
|
@ -108,7 +108,14 @@ class Converter(TinyObj):
|
||||
@staticmethod
|
||||
def toBGR888(image: Image):
|
||||
"""Convert the image to BGR888"""
|
||||
|
||||
def converter(image:Image,format:int):
|
||||
"""
|
||||
2:RGB888
|
||||
3:BGR888
|
||||
4:RGB565
|
||||
5:GRAY
|
||||
6:BMP
|
||||
"""
|
||||
|
||||
class Transforms(TinyObj):
|
||||
"""The transforms class is used to
|
||||
|
@ -419,3 +419,28 @@ void PikaCV_Converter_toBGR888(PikaObj* self, PikaObj* image) {
|
||||
img->size = size_new;
|
||||
arg_deinit(arg_data_new);
|
||||
}
|
||||
|
||||
void PikaCV_Converter_converter(PikaObj *self, int format, PikaObj* image){
|
||||
switch (format)
|
||||
{
|
||||
case PikaCV_ImageFormat_Type_RGB888:
|
||||
PikaCV_Converter_toRGB888(self,image);
|
||||
break;
|
||||
case PikaCV_ImageFormat_Type_BGR888:
|
||||
PikaCV_Converter_toBGR888(self,image);
|
||||
break;
|
||||
case PikaCV_ImageFormat_Type_RGB565:
|
||||
PikaCV_Converter_toRGB565(self,image);
|
||||
break;
|
||||
case PikaCV_ImageFormat_Type_GRAY:
|
||||
PikaCV_Converter_toGray(self,image);
|
||||
break;
|
||||
case PikaCV_ImageFormat_Type_BMP:
|
||||
PikaCV_Converter_toBMP(self,image);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
@ -10,7 +10,7 @@ void PikaCV_Image___init__(PikaObj* self) {
|
||||
}
|
||||
/* init */
|
||||
PikaCV_Image image = {
|
||||
.format = PikaCV_ImageFormat_Type_Unknown,
|
||||
.format = PikaCV_ImageFormat_Type_Empty,
|
||||
.width = 0,
|
||||
.height = 0,
|
||||
.size = 0,
|
||||
@ -56,7 +56,7 @@ Arg* PikaCV_Image_data(PikaObj* self) {
|
||||
int PikaCV_Image_format(PikaObj* self) {
|
||||
PikaCV_Image* image = obj_getStruct(self, "image");
|
||||
if (NULL == image) {
|
||||
return PikaCV_ImageFormat_Type_Unknown;
|
||||
return PikaCV_ImageFormat_Type_Empty;
|
||||
}
|
||||
return image->format;
|
||||
}
|
||||
@ -232,15 +232,15 @@ void PikaCV_Image_add(PikaObj* self, PikaObj* image) {
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (img->format != src->format) {
|
||||
if(!PikaCV_Format_CheckTwo(self,image,PikaCV_Check_ReturnError)){
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("unsupported image format\n");
|
||||
return;
|
||||
}
|
||||
if (img->size != src->size) {
|
||||
if(!PikaCV_Size_Check(self,image,PikaCV_Check_SHW)){
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("illegal image size\n");
|
||||
return;
|
||||
__platform_printf("illegal image size\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
uint8_t* src_data = _image_getData(self);
|
||||
@ -276,15 +276,15 @@ void PikaCV_Image_minus(PikaObj* self, PikaObj* image) {
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (img->format != src->format) {
|
||||
if(!PikaCV_Format_CheckTwo(self,image,PikaCV_Check_ReturnError)){
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("unsupported image format\n");
|
||||
return;
|
||||
}
|
||||
if (img->size != src->size) {
|
||||
if(!PikaCV_Size_Check(self,image,PikaCV_Check_SHW)){
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("illegal image size\n");
|
||||
return;
|
||||
__platform_printf("illegal image size\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
uint8_t* src_data = _image_getData(self);
|
||||
@ -324,20 +324,20 @@ void PikaCV_Image_merge(PikaObj* self, PikaObj* B, PikaObj* G, PikaObj* R) {
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (PikaCV_ImageFormat_Type_RGB888 != src->format) {
|
||||
if (!PikaCV_Format_Check(self,PikaCV_ImageFormat_Type_RGB888,PikaCV_Check_ReturnError)) {
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("unsupported image format\n");
|
||||
return;
|
||||
}
|
||||
if (PikaCV_ImageFormat_Type_GRAY != Channel_B->format ||
|
||||
PikaCV_ImageFormat_Type_GRAY != Channel_G->format ||
|
||||
PikaCV_ImageFormat_Type_GRAY != Channel_R->format) {
|
||||
if (!PikaCV_Format_Check(B,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_ReturnError) ||
|
||||
!PikaCV_Format_Check(G,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_ReturnError) ||
|
||||
!PikaCV_Format_Check(R,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_ReturnError)) {
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("unsupported image format\n");
|
||||
return;
|
||||
}
|
||||
if (Channel_B->size != Channel_G->size ||
|
||||
Channel_B->size != Channel_R->size) {
|
||||
if (!PikaCV_Size_Check(B,G,PikaCV_Check_SHW) ||
|
||||
!PikaCV_Size_Check(B,R,PikaCV_Check_SHW)) {
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("illegal image size\n");
|
||||
return;
|
||||
@ -371,7 +371,7 @@ PikaObj* PikaCV_Image_split(PikaObj* self) {
|
||||
pika_assert(0);
|
||||
return NULL;
|
||||
}
|
||||
if (PikaCV_ImageFormat_Type_RGB888 != src->format) {
|
||||
if(!PikaCV_Format_Check(self,PikaCV_ImageFormat_Type_RGB888,PikaCV_Check_ReturnError)){
|
||||
obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
__platform_printf("unsupported image format\n");
|
||||
return NULL;
|
||||
|
@ -48,10 +48,7 @@ void PikaCV_Transforms_threshold(PikaObj* self,
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (src->format != PikaCV_ImageFormat_Type_GRAY) {
|
||||
PikaCV_Converter_toGray(self, image);
|
||||
}
|
||||
|
||||
PikaCV_Format_Check(image,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_Converter);
|
||||
uint8_t* src_data = _image_getData(image);
|
||||
|
||||
int i;
|
||||
@ -99,9 +96,7 @@ void PikaCV_Transforms_setROI(PikaObj* self,
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (src->format != PikaCV_ImageFormat_Type_RGB888) {
|
||||
PikaCV_Converter_toRGB888(self, image);
|
||||
}
|
||||
PikaCV_Format_Check(image,PikaCV_ImageFormat_Type_RGB888,PikaCV_Check_Converter);
|
||||
if (x <= 0 || y <= 0 || w <= 0 || h <= 0) {
|
||||
pika_assert(0);
|
||||
return;
|
||||
@ -141,9 +136,7 @@ int PikaCV_Transforms_getOTSUthre(PikaObj* self, PikaObj* image) {
|
||||
pika_assert(0);
|
||||
return 0;
|
||||
}
|
||||
if (src->format != PikaCV_ImageFormat_Type_GRAY) {
|
||||
PikaCV_Converter_toGray(self, image);
|
||||
}
|
||||
PikaCV_Format_Check(image,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_Converter);
|
||||
const int Grayscale = 256;
|
||||
int width = src->width;
|
||||
int height = src->height;
|
||||
@ -190,10 +183,7 @@ void PikaCV_Transforms_setOTSU(PikaObj* self, PikaObj* image) {
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (src->format != PikaCV_ImageFormat_Type_GRAY) {
|
||||
PikaCV_Converter_toGray(self, image);
|
||||
}
|
||||
|
||||
PikaCV_Format_Check(image,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_Converter);
|
||||
int thre = PikaCV_Transforms_getOTSUthre(self, image);
|
||||
uint8_t* src_data = _image_getData(image);
|
||||
|
||||
@ -224,9 +214,7 @@ void PikaCV_Transforms_resize(PikaObj* self,
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (src->format != PikaCV_ImageFormat_Type_RGB888) {
|
||||
PikaCV_Converter_toRGB888(self, image);
|
||||
}
|
||||
PikaCV_Format_Check(image,PikaCV_ImageFormat_Type_RGB888,PikaCV_Check_Converter);
|
||||
|
||||
int size_new = x * y * 3;
|
||||
Arg* arg_data_new = arg_setBytes(NULL, "", NULL, size_new);
|
||||
@ -278,10 +266,7 @@ void PikaCV_Transforms_adaptiveThreshold(PikaObj* self,
|
||||
pika_assert(0);
|
||||
return;
|
||||
}
|
||||
if (src->format != PikaCV_ImageFormat_Type_GRAY) {
|
||||
PikaCV_Converter_toGray(self, image);
|
||||
}
|
||||
|
||||
PikaCV_Format_Check(image,PikaCV_ImageFormat_Type_GRAY,PikaCV_Check_Converter);
|
||||
int size = src->size;
|
||||
uint8_t* src_data = _image_getData(image);
|
||||
uint8_t* src_copy;
|
||||
|
@ -0,0 +1,107 @@
|
||||
#include "PikaCV_common.h"
|
||||
#include "PikaCV_Converter.h"
|
||||
|
||||
int PikaCV_Format_Check(PikaObj* image,PikaCV_ImageFormat_Type type,PikaCV_Check_ReturnMode returnMode){
|
||||
// return mode: 0
|
||||
// 1
|
||||
// 2
|
||||
//PikaObj* self;
|
||||
|
||||
PikaCV_Image* src = obj_getStruct(image, "image");
|
||||
switch (returnMode)
|
||||
{
|
||||
case PikaCV_Check_ReturnError:
|
||||
if(src->format != type){
|
||||
//obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case PikaCV_Check_Converter:
|
||||
/* code */
|
||||
if(src->format != type){
|
||||
PikaCV_Converter_converter((PikaObj*)NULL,type,image);
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int PikaCV_Format_CheckTwo(PikaObj* image1,PikaObj* image2,PikaCV_Check_ReturnMode returnMode){
|
||||
//PikaObj* self;
|
||||
|
||||
PikaCV_Image* src1 = obj_getStruct(image1, "image");
|
||||
PikaCV_Image* src2 = obj_getStruct(image2, "image");
|
||||
|
||||
switch (returnMode)
|
||||
{
|
||||
case PikaCV_Check_ReturnError:
|
||||
if(src1->format != src2->format){
|
||||
//obj_setErrorCode(self, PIKA_RES_ERR_OPERATION_FAILED);
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case PikaCV_Check_Converter:
|
||||
/* code */
|
||||
if(src1->format != src2->format){
|
||||
PikaCV_Converter_converter((PikaObj*)NULL,src1->format,image2);
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PikaCV_Size_Check(PikaObj* image1,PikaObj* image2,PikaCV_Check_SizeMode sizeMode){
|
||||
//sPikaObj* self;
|
||||
|
||||
PikaCV_Image* src1 = obj_getStruct(image1, "image");
|
||||
PikaCV_Image* src2 = obj_getStruct(image2, "image");
|
||||
|
||||
switch (sizeMode)
|
||||
{
|
||||
case PikaCV_Check_Size:
|
||||
/* code */
|
||||
if(src1->size != src2->size){
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case PikaCV_Check_SHW:
|
||||
/* code */
|
||||
if(src1->size != src2->size || src1->height!= src2->height || src1->width != src2->width){
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case PikaCV_Check_HW:
|
||||
/* code */
|
||||
if(src1->height!= src2->height || src1->width != src2->width){
|
||||
return 0;
|
||||
}else{
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
#include "./3rd-party/tjpgd/src/tjpgd.h"
|
||||
#include "PikaObj.h"
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
typedef enum PikaCV_ImageFormat_Type {
|
||||
PikaCV_ImageFormat_Type_Unknown = 0,
|
||||
PikaCV_ImageFormat_Type_Empty = 0,
|
||||
PikaCV_ImageFormat_Type_JPEG,
|
||||
PikaCV_ImageFormat_Type_RGB888,
|
||||
PikaCV_ImageFormat_Type_BGR888,
|
||||
@ -18,6 +19,21 @@ typedef struct PikaCV_Image {
|
||||
int size;
|
||||
} PikaCV_Image;
|
||||
|
||||
typedef enum {
|
||||
PikaCV_Check_ReturnError = 0,
|
||||
PikaCV_Check_Converter,
|
||||
} PikaCV_Check_ReturnMode;
|
||||
|
||||
typedef enum {
|
||||
PikaCV_Check_Size = 0,
|
||||
PikaCV_Check_SHW,
|
||||
PikaCV_Check_HW,
|
||||
} PikaCV_Check_SizeMode;
|
||||
|
||||
uint8_t* _image_getData(PikaObj* self);
|
||||
PIKA_RES _image_setData(PikaObj* self, uint8_t* data, int size);
|
||||
int _image_getDataSize(PikaObj* self);
|
||||
int _image_getDataSize(PikaObj* self);
|
||||
|
||||
int PikaCV_Format_Check(PikaObj* image,PikaCV_ImageFormat_Type type,PikaCV_Check_ReturnMode returnMode);
|
||||
int PikaCV_Format_CheckTwo(PikaObj* image1,PikaObj* image2,PikaCV_Check_ReturnMode returnMode);
|
||||
int PikaCV_Size_Check(PikaObj* image1,PikaObj* image2,PikaCV_Check_SizeMode sizeMode);
|
Loading…
x
Reference in New Issue
Block a user