@ -18,9 +18,11 @@
# include <android/log.h>
# include <android/thermal.h>
# include <android/imagedecoder.h>
# include <sys/system_properties.h>
# include <mat.h>
# include <fcntl.h>
# include <filesystem>
namespace fs = std : : filesystem ;
@ -1333,7 +1335,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
TurnOnCameraPower ( NULL ) ;
res = true ;
if ( mPhotoInfo . mediaType = = 0 )
if ( mPhotoInfo . mediaType = = 0 & & mPhotoInfo . usingRawFormat = = 0 )
{
mCamera = new CPhoneCamera ( this , photoInfo . width , photoInfo . height , params ) ;
// mCamera = new CJpegCamera(this, photoInfo.width, photoInfo.height, mPath, params);
@ -1395,9 +1397,9 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
}
int orientation = mPhotoInfo . orientation = = 0 ? - 1 : ( mPhotoInfo . orientation - 1 ) * 90 ;
jboolean photoOrVideo = JNI_FALSE;
jboolean photoOrVideo = mPhotoInfo. mediaType = = 0 ? JNI_TRUE : JNI_FALSE;
env - > CallVoidMethod ( m_javaService , mStartRecordingMid , photoOrVideo , mPhotoInfo . cameraId , ( unsigned long ) mPhotoInfo . photoId ,
mPhotoInfo . duration , mPhotoInfo . width , mPhotoInfo . height , mPhotoInfo . duration , orientation ,
mPhotoInfo . duration , mPhotoInfo . width , mPhotoInfo . height , mPhotoInfo . duration , orientation ,
leftTopOSD , rightTopOSD , rightBottomOSD , leftBottomOSD ) ;
if ( leftTopOSD ) env - > DeleteLocalRef ( leftTopOSD ) ;
@ -1479,12 +1481,6 @@ void DrawOutlineText(cv::Ptr<cv::ft::FreeType2> ft2, cv::Mat& mat, const std::st
bool CPhoneDevice : : OnImageReady ( cv : : Mat & mat )
{
if ( mCamera = = NULL )
{
// int aa = 0;
return false ;
}
time_t takingTime = time ( NULL ) ;
if ( mPhotoInfo . remedy ! = 0 )
{
@ -1623,49 +1619,51 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
// #ifdef OUTPUT_CAMERA_DBG_INFO
NdkCamera : : CAPTURE_RESULT captureResult = mCamera - > getCaptureResult ( ) ;
if ( mPhotoInfo . outputDbgInfo ! = 0 )
if ( mCamera ! = NULL )
{
cv: : Scalar scalarRed ( 0 , 0 , 255 ) ; // red
NdkCamera : : CAPTURE_RESULT captureResult = mCamera - > getCaptureResult ( ) ;
char extimeunit [ 4 ] = { 0 } ;
unsigned int extime = ( captureResult . exposureTime > = 1000000 ) ? ( ( unsigned int ) ( captureResult . exposureTime / 1000000 ) ) : ( ( unsigned int ) ( captureResult . exposureTime / 1000 ) ) ;
strcpy ( extimeunit , ( captureResult . exposureTime > = 1000000 ) ? " ms " : " μs " ) ;
char str [ 128 ] = { 0 } ;
snprintf ( str , sizeof ( str ) , " AE=%u AF=%u EXPS=%u%s(%d) ISO=%d AFS=%u AES=%u AWBS=%u SCENE=%d LDR=%d(%u) %0.1fx T=%u FD=%lld " ,
captureResult . autoExposure , captureResult . autoFocus ,
extime , extimeunit , captureResult . compensation , captureResult . sensitivity ,
// isnan(captureResult.FocusDistance) ? 0 : captureResult.FocusDistance,
( unsigned int ) captureResult . afState , ( unsigned int ) captureResult . aeState , captureResult . awbState ,
captureResult . sceneMode , GpioControl : : getLightAdc ( ) , ( unsigned int ) captureResult . avgY , captureResult . zoomRatio ,
( uint32_t ) captureResult . duration , captureResult . frameDuration ) ;
// cv::putText(mat, str, cv::Point(0, mat.rows - 20), cv::FONT_HERSHEY_COMPLEX, fontScale, scalarWhite, thickness1, cv::LINE_AA);
if ( mPhotoInfo . outputDbgInfo ! = 0 )
{
cv : : Scalar scalarRed ( 0 , 0 , 255 ) ; // red
int fs = fontSize * 2 / 3 ;
textSize = ft2 - > getTextSize ( str , fs , - 1 , & baseline ) ;
cv : : Point lt ( 0 , mat . rows - fs - 20 * ratio ) ;
cv : : Point lt2 ( 0 , lt . y - 2 * ratio ) ;
cv : : Point rb ( 0 + textSize . width + 2 * ratio , lt2 . y + textSize . height + 8 * ratio ) ;
char extimeunit [ 4 ] = { 0 } ;
unsigned int extime = ( captureResult . exposureTime > = 1000000 ) ? ( ( unsigned int ) ( captureResult . exposureTime / 1000000 ) ) : ( ( unsigned int ) ( captureResult . exposureTime / 1000 ) ) ;
strcpy ( extimeunit , ( captureResult . exposureTime > = 1000000 ) ? " ms " : " μs " ) ;
char str [ 128 ] = { 0 } ;
snprintf ( str , sizeof ( str ) , " AE=%u AF=%u EXPS=%u%s(%d) ISO=%d AFS=%u AES=%u AWBS=%u SCENE=%d LDR=%d(%u) %0.1fx T=%u FD=%lld " ,
captureResult . autoExposure , captureResult . autoFocus ,
extime , extimeunit , captureResult . compensation , captureResult . sensitivity ,
// isnan(captureResult.FocusDistance) ? 0 : captureResult.FocusDistance,
( unsigned int ) captureResult . afState , ( unsigned int ) captureResult . aeState , captureResult . awbState ,
captureResult . sceneMode , GpioControl : : getLightAdc ( ) , ( unsigned int ) captureResult . avgY , captureResult . zoomRatio ,
( uint32_t ) captureResult . duration , captureResult . frameDuration ) ;
// cv::putText(mat, str, cv::Point(0, mat.rows - 20), cv::FONT_HERSHEY_COMPLEX, fontScale, scalarWhite, thickness1, cv::LINE_AA);
if ( rb . x > ( int ) width - 1 )
{
rb . x = ( int ) width - 1 ;
}
if ( rb . y > ( int ) height - 1 )
{
rb . y = ( int ) height - 1 ;
}
cv : : Mat roi = mat ( cv : : Rect ( lt2 , rb ) ) ;
cv : : Mat clrMat ( roi . size ( ) , CV_8UC3 , scalarWhite ) ;
double alpha = 0.5 ;
cv : : addWeighted ( clrMat , alpha , roi , 1.0 - alpha , 0.0 , roi ) ;
int fs = fontSize * 2 / 3 ;
textSize = ft2 - > getTextSize ( str , fs , - 1 , & baseline ) ;
cv : : Point lt ( 0 , mat . rows - fs - 20 * ratio ) ;
cv : : Point lt2 ( 0 , lt . y - 2 * ratio ) ;
cv : : Point rb ( 0 + textSize . width + 2 * ratio , lt2 . y + textSize . height + 8 * ratio ) ;
// cv::rectangle(mat, lt2, rb,cv::Scalar(255, 255, 255), -1);
ft2 - > putText ( mat , str , lt , fs , scalarRed , - 1 , cv : : LINE_AA , false ) ;
// DrawOutlineText(ft2, mat, str, cv::Point(0, mat.rows - fs - 20 * ratio), fs, scalarWhite, 1);
}
if ( rb . x > ( int ) width - 1 )
{
rb . x = ( int ) width - 1 ;
}
if ( rb . y > ( int ) height - 1 )
{
rb . y = ( int ) height - 1 ;
}
cv : : Mat roi = mat ( cv : : Rect ( lt2 , rb ) ) ;
cv : : Mat clrMat ( roi . size ( ) , CV_8UC3 , scalarWhite ) ;
double alpha = 0.5 ;
cv : : addWeighted ( clrMat , alpha , roi , 1.0 - alpha , 0.0 , roi ) ;
// cv::rectangle(mat, lt2, rb,cv::Scalar(255, 255, 255), -1);
ft2 - > putText ( mat , str , lt , fs , scalarRed , - 1 , cv : : LINE_AA , false ) ;
// DrawOutlineText(ft2, mat, str, cv::Point(0, mat.rows - fs - 20 * ratio), fs, scalarWhite, 1);
}
}
// #endif // OUTPUT_CAMERA_DBG_INFO
for ( vector < OSD_INFO > : : const_iterator it = mOsds . cbegin ( ) ; it ! = mOsds . cend ( ) ; + + it )
@ -1722,6 +1720,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
bool shouldRetry = false ;
#if 0
if ( captureResult . avgY > MAX_LIGHT_Y | | captureResult . avgY < MIN_LIGHT_Y )
{
if ( mPhotoInfo . retries < ( DEFAULT_TAKE_PHOTO_RETRIES - 1 ) )
@ -1790,20 +1789,72 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
bool CPhoneDevice : : OnVideoReady ( bool photoOrVideo , bool result , const char * path , unsigned int photoId )
{
mPhotoInfo . photoTime = time ( NULL ) ;
CPhoneCamera * pCamera = NULL ;
std : : vector < IDevice : : RECOG_OBJECT > objs ;
std : : string fullPath = mPath + CTerminal : : BuildPhotoFileName ( mPhotoInfo ) ;
if ( result )
if ( photoOrVideo )
{
std : : rename ( path , fullPath . c_str ( ) ) ;
AImageDecoder * decoder = NULL ;
int fd = open ( path , O_RDONLY ) ;
if ( fd = = - 1 )
{
}
int result = AImageDecoder_createFromFd ( fd , & decoder ) ;
if ( result ! = ANDROID_IMAGE_DECODER_SUCCESS )
{
}
auto decoder_cleanup = [ & decoder ] ( ) {
AImageDecoder_delete ( decoder ) ;
} ;
const AImageDecoderHeaderInfo * header_info = AImageDecoder_getHeaderInfo ( decoder ) ;
int bitmap_format = AImageDecoderHeaderInfo_getAndroidBitmapFormat ( header_info ) ;
// This is just for example. I don't want to handle other cases in this
// example, but that should be easy enough to do.
if ( bitmap_format ! = ANDROID_BITMAP_FORMAT_RGBA_8888 )
{
decoder_cleanup ( ) ;
}
constexpr int kChannels = 4 ;
int width = AImageDecoderHeaderInfo_getWidth ( header_info ) ;
int height = AImageDecoderHeaderInfo_getHeight ( header_info ) ;
size_t stride = AImageDecoder_getMinimumStride ( decoder ) ;
size_t size = stride * height ;
std : : vector < uint8_t > pixels ;
pixels . resize ( size , 0 ) ;
int decode_result = AImageDecoder_decodeImage ( decoder , & pixels [ 0 ] , stride , size ) ;
if ( decode_result ! = ANDROID_IMAGE_DECODER_SUCCESS )
{
decoder_cleanup ( ) ;
return false ;
}
cv : : Mat mat ( height , width , CV_8UC4 , ( void * ) & pixels [ 0 ] ) ;
OnImageReady ( mat ) ;
decoder_cleanup ( ) ;
close ( fd ) ;
}
TakePhotoCb ( result , mPhotoInfo , fullPath , time ( NULL ) , objs ) ;
else
{
mPhotoInfo . photoTime = time ( NULL ) ;
CPhoneCamera * pCamera = NULL ;
bool turnOffOtg = ( mPhotoInfo . usbCamera ! = 0 ) ;
std : : thread closeThread ( & CPhoneDevice : : CloseCamera2 , this , pCamera , mPhotoInfo . photoId , turnOffOtg ) ;
m_threadClose . swap ( closeThread ) ;
std : : vector < IDevice : : RECOG_OBJECT > objs ;
std : : string fullPath = mPath + CTerminal : : BuildPhotoFileName ( mPhotoInfo ) ;
if ( result )
{
std : : rename ( path , fullPath . c_str ( ) ) ;
}
TakePhotoCb ( result , mPhotoInfo , fullPath , time ( NULL ) , objs ) ;
bool turnOffOtg = ( mPhotoInfo . usbCamera ! = 0 ) ;
std : : thread closeThread ( & CPhoneDevice : : CloseCamera2 , this , pCamera , mPhotoInfo . photoId , turnOffOtg ) ;
m_threadClose . swap ( closeThread ) ;
}
return result ;
}