Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mxn_sensor: return hsv [WIP] #6

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions ov7670/mxn_sensor/include/internal/module_ce.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ int codecEngineStop(CodecEngine* _ce);

int codecEngineTranscodeFrame(CodecEngine* _ce,
const void* _srcFramePtr, size_t _srcFrameSize,
bool _returnHSV,
void* _dstFramePtr, size_t _dstFrameSize, size_t* _dstFrameUsed,
const TargetDetectParams* _targetDetectParams,
const TargetDetectCommand* _targetDetectCommand,
Expand Down
5 changes: 5 additions & 0 deletions ov7670/mxn_sensor/include/internal/module_rc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ typedef struct RCConfig // what user wants to set
const char* m_fifoInput;
const char* m_fifoOutput;
bool m_videoOutEnable;
bool m_returnHSV;
MxnParams m_mxnParams;
} RCConfig;

Expand Down Expand Up @@ -45,6 +46,9 @@ typedef struct RCInput

bool m_mxnParamsUpdated;
MxnParams m_mxnParams;

bool m_returnHSVUpdated;
bool m_returnHSV;
} RCInput;


Expand All @@ -64,6 +68,7 @@ int rcInputGetTargetDetectParams(RCInput* _rc, TargetDetectParams* _targetDetect
int rcInputGetTargetDetectCommand(RCInput* _rc, TargetDetectCommand* _targetDetectCommand);

int rcInputGetVideoOutParams(RCInput* _rc, bool *_videoOutEnable);
int rcInputGetBoolReturnHSVParams(RCInput* _rc, bool *_returnHSV);
int rcInputUnsafeReportTargetColors(RCInput* _rc, const TargetColors* _targetColors);

int rcInputUnsafeReportTargetLocation(RCInput* _rc, const TargetLocation* _targetLocation);
Expand Down
5 changes: 4 additions & 1 deletion ov7670/mxn_sensor/include/internal/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ typedef struct RuntimeState
TargetDetectParams m_targetDetectParams;
TargetDetectCommand m_targetDetectCommand;
bool m_videoOutEnable;
MxnParams m_mxnParams
MxnParams m_mxnParams;
bool m_returnHSV;
} RuntimeState;

typedef struct Runtime
Expand Down Expand Up @@ -93,6 +94,8 @@ int runtimeGetVideoOutParams(Runtime* _runtime, bool* _videoOutEnable);
int runtimeSetVideoOutParams(Runtime* _runtime, const bool* _videoOutEnable);
int runtimeGetMxnParams(Runtime* _runtime, MxnParams* _mxnParams);
int runtimeSetMxnParams(Runtime* _runtime, MxnParams* _mxnParams);
int runtimeGetBoolReturnHSV(Runtime* _runtime, bool* _returnHSV);
int runtimeSetBoolReturnHSV(Runtime* _runtime, bool* _returnHSV);

int runtimeReportTargetLocation(Runtime* _runtime, const TargetLocation* _targetLocation);
int runtimeReportTargetColors(Runtime* _runtime, const TargetColors* _targetColors);
Expand Down
7 changes: 6 additions & 1 deletion ov7670/mxn_sensor/src/module_ce.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ static int makeValueWrap(int _val, int _adj, int _min, int _max)

static int do_transcodeFrame(CodecEngine* _ce,
const void* _srcFramePtr, size_t _srcFrameSize,
bool _returnHSV,
void* _dstFramePtr, size_t _dstFrameSize, size_t* _dstFrameUsed,
const TargetDetectParams* _targetDetectParams,
const TargetDetectCommand* _targetDetectCommand,
Expand All @@ -220,6 +221,7 @@ static int do_transcodeFrame(CodecEngine* _ce,

tcInArgs.alg.widthM = _ce->m_mxnParams.m_m;
tcInArgs.alg.heightN = _ce->m_mxnParams.m_n;
tcInArgs.alg.isHSV = _returnHSV;


TRIK_VIDTRANSCODE_CV_OutArgs tcOutArgs;
Expand Down Expand Up @@ -249,6 +251,7 @@ static int do_transcodeFrame(CodecEngine* _ce,
Memory_cacheInv(_ce->m_dstBuffer, _ce->m_dstBufferSize); // invalidate *whole* cache, not only expected portion, just in case

XDAS_Int32 processResult = VIDTRANSCODE_process(_ce->m_vidtranscodeHandle, &tcInBufDesc, &tcOutBufDesc, &tcInArgs.base, &tcOutArgs.base);

if (processResult != IVIDTRANSCODE_EOK)
{
fprintf(stderr, "VIDTRANSCODE_process(%zu -> %zu) failed: %"PRIi32"/%"PRIi32"\n",
Expand Down Expand Up @@ -284,6 +287,7 @@ static int do_transcodeFrame(CodecEngine* _ce,
return 0;
}


static int do_reportLoad(const CodecEngine* _ce, long long _ms)
{
(void)_ms; // warn prevention
Expand Down Expand Up @@ -434,6 +438,7 @@ int codecEngineStop(CodecEngine* _ce)

int codecEngineTranscodeFrame(CodecEngine* _ce,
const void* _srcFramePtr, size_t _srcFrameSize,
bool _returnHSV,
void* _dstFramePtr, size_t _dstFrameSize, size_t* _dstFrameUsed,
const TargetDetectParams* _targetDetectParams,
const TargetDetectCommand* _targetDetectCommand,
Expand All @@ -449,7 +454,7 @@ int codecEngineTranscodeFrame(CodecEngine* _ce,
return ENOTCONN;

res = do_transcodeFrame(_ce,
_srcFramePtr, _srcFrameSize,
_srcFramePtr, _srcFrameSize, _returnHSV,
_dstFramePtr, _dstFrameSize, _dstFrameUsed,
_targetDetectParams,
_targetDetectCommand,
Expand Down
18 changes: 18 additions & 0 deletions ov7670/mxn_sensor/src/module_rc.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ static int do_readFifoInput(RCInput* _rc)
_rc->m_targetDetectCommand = 1;
_rc->m_targetDetectCommandUpdated = true;
}
else if (strncmp(parseAt, "hsv", strlen("hsv")) == 0)
{
_rc->m_returnHSV = true;
_rc->m_returnHSVUpdated = true;
}
else if (strncmp(parseAt, "hsv ", strlen("hsv ")) == 0)
{
int hue, hueTol, sat, satTol, val, valTol;
Expand Down Expand Up @@ -382,6 +387,7 @@ int rcInputOpen(RCInput* _rc, const RCConfig* _config)

_rc->m_videoOutEnable = _config->m_videoOutEnable;
_rc->m_mxnParams = _config->m_mxnParams;
_rc->m_returnHSV = _config->m_returnHSV;
return 0;
}

Expand Down Expand Up @@ -489,6 +495,18 @@ int rcInputGetMxnParams(RCInput* _rc,
return 0;
}

int rcInputGetBoolReturnHSVParams(RCInput* _rc, bool *_returnHSV)
{
if (_rc == NULL || _returnHSV == NULL)
return EINVAL;

_rc->m_returnHSVUpdated = false;
*_returnHSV = _rc->m_returnHSV;
//fprintf(stderr, "rcInputGetBoolReturnHSVParams has been invoke. _returnHSV = %d\n", *_returnHSV);

return 0;
}

int rcInputGetTargetDetectCommand(RCInput* _rc, TargetDetectCommand* _targetDetectCommand)
{
if (_rc == NULL || _targetDetectCommand == NULL)
Expand Down
Binary file modified ov7670/mxn_sensor/src/mxn_sensor_arm
Binary file not shown.
29 changes: 28 additions & 1 deletion ov7670/mxn_sensor/src/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static const RuntimeConfig s_runtimeConfig = {
.m_codecEngineConfig = { "dsp_server.xe674", "vidtranscode_cv"},
.m_v4l2Config = { "/dev/video0", 320, 240, V4L2_PIX_FMT_YUV422P },
.m_fbConfig = { "/dev/fb0" },
.m_rcConfig = { "/run/mxn-sensor.in.fifo", "/run/mxn-sensor.out.fifo", true, {3, 3}}
.m_rcConfig = { "/run/mxn-sensor.in.fifo", "/run/mxn-sensor.out.fifo", true, false, {3, 3}}
};


Expand Down Expand Up @@ -70,6 +70,7 @@ bool runtimeParseArgs(Runtime* _runtime, int _argc, char* const _argv[])
{ "video-out", 1, NULL, 0 }, //7+2
{ "mxn-width-m", 1, NULL, 0 }, //7+3
{ "mxn-height-n", 1, NULL, 0 }, //7+4
{ "hsv", 0, NULL, 0 }, //7+5
{ "verbose", 0, NULL, 'v' },
{ "help", 0, NULL, 'h' },
{ NULL, 0, NULL, 0 }
Expand Down Expand Up @@ -125,12 +126,14 @@ bool runtimeParseArgs(Runtime* _runtime, int _argc, char* const _argv[])
_runtime->m_modules.m_rcInput.m_mxnParams.m_n =
atoi(optarg) < COLORS_HEIGHTN_MAX ? atoi(optarg) : COLORS_HEIGHTN_MAX;
break;
case 7+5: cfg->m_rcConfig.m_returnHSV = true; break;

default:
return false;
}
break;


case 'h':
default:
return false;
Expand Down Expand Up @@ -165,6 +168,8 @@ void runtimeArgsHelpMessage(Runtime* _runtime, const char* _arg0)
" --mxn-width-m <mxn-width-m>\n"
" --mxn-height-n <mxn-heigth-n>\n"

" --hsv\n"

" --verbose\n"
" --help\n",
_arg0);
Expand Down Expand Up @@ -465,6 +470,28 @@ int runtimeSetMxnParams(Runtime* _runtime, MxnParams* _mxnParams)
return 0;
}

int runtimeGetBoolReturnHSVParams(Runtime* _runtime, bool* _returnHSV)
{
if (_runtime == NULL || _returnHSV == NULL)
return EINVAL;

pthread_mutex_lock(&_runtime->m_state.m_mutex);
*_returnHSV = _runtime->m_state.m_returnHSV;
pthread_mutex_unlock(&_runtime->m_state.m_mutex);
return 0;
}

int runtimeSetBoolReturnHSVParams(Runtime* _runtime, bool* _returnHSV)
{
if (_runtime == NULL || _returnHSV == NULL)
return EINVAL;

pthread_mutex_lock(&_runtime->m_state.m_mutex);
_runtime->m_state.m_returnHSV = *_returnHSV;
pthread_mutex_unlock(&_runtime->m_state.m_mutex);
return 0;
}


int runtimeFetchTargetDetectCommand(Runtime* _runtime, TargetDetectCommand* _targetDetectCommand)
{
Expand Down
18 changes: 18 additions & 0 deletions ov7670/mxn_sensor/src/thread_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ static int threadInputSelectLoop(Runtime* _runtime, RCInput* _rc)
}
}

bool returnHSV;
if ((res = rcInputGetBoolReturnHSVParams(_rc, &returnHSV)) != 0)
{
if (res != ENODATA)
{
fprintf(stderr, "rcInputGetBoolReturnHSVParams() failed: %d\n", res);
return res;
}
}
else
{
if ((res = runtimeSetBoolReturnHSVParams(_runtime, &returnHSV)) != 0)
{
fprintf(stderr, "runtimeSetReturnHSVParams() failed: %d\n", res);
return res;
}
}

TargetDetectCommand targetDetectCommand;
if ((res = rcInputGetTargetDetectCommand(_rc, &targetDetectCommand)) != 0)
{
Expand Down
10 changes: 9 additions & 1 deletion ov7670/mxn_sensor/src/thread_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ static int threadVideoSelectLoop(Runtime* _runtime, CodecEngine* _ce, V4L2Input*
TargetDetectParams targetDetectParamsResult;
TargetColors targetColors;
MxnParams mxnParams;
bool returnHSV;

if ((res = runtimeGetTargetDetectParams(_runtime, &targetDetectParams)) != 0)
{
fprintf(stderr, "runtimeGetTargetDetectParams() failed: %d\n", res);
Expand All @@ -78,6 +80,12 @@ static int threadVideoSelectLoop(Runtime* _runtime, CodecEngine* _ce, V4L2Input*
fprintf(stderr, "runtimeFetchTargetDetectCommand() failed: %d\n", res);
return res;
}

if ((res = runtimeGetBoolReturnHSVParams(_runtime, &returnHSV)) != 0)
{
fprintf(stderr, "runtimeGetBoolReturnHSV() failed: %d\n", res);
return res;
}

if ((res = runtimeGetVideoOutParams(_runtime, &(_ce->m_videoOutEnable))) != 0)
{
Expand All @@ -94,7 +102,7 @@ static int threadVideoSelectLoop(Runtime* _runtime, CodecEngine* _ce, V4L2Input*

size_t frameDstUsed = frameDstSize;
if ((res = codecEngineTranscodeFrame(_ce,
frameSrcPtr, frameSrcSize,
frameSrcPtr, frameSrcSize, returnHSV,
frameDstPtr, frameDstSize, &frameDstUsed,
&targetDetectParams,
&targetDetectCommand,
Expand Down