|
|
|
@ -431,6 +431,8 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
|
|
|
|
|
mEnableGpsMid = env->GetMethodID(classService, "enableGps", "(Z)V");
|
|
|
|
|
mRequestPositionMid = env->GetMethodID(classService, "requestPosition", "()Z");
|
|
|
|
|
|
|
|
|
|
mExecHdrplusMid = env->GetMethodID(classService, "execHdrplus", "(IILjava/lang/String;Ljava/lang/String;)I");
|
|
|
|
|
|
|
|
|
|
env->DeleteLocalRef(classService);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -441,6 +443,7 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
|
|
|
|
|
|
|
|
|
|
m_timerUidFeed = time(NULL) * 1000;
|
|
|
|
|
m_wakelockIdFeed = (unsigned long)m_timerUidFeed;
|
|
|
|
|
m_uniqueIdFeed = (unsigned long)m_timerUidFeed;
|
|
|
|
|
|
|
|
|
|
#ifdef USING_NRSEC
|
|
|
|
|
TurnOnCameraPower(env);
|
|
|
|
@ -502,7 +505,7 @@ void CPhoneDevice::SetRecognizationCfg(const IDevice::CFG_RECOGNIZATION* pRecogn
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_INFO, "AI Enabled");
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_INFO, "AI Enabled and will Init NCNN");
|
|
|
|
|
ncnn_init();
|
|
|
|
|
mAIInitialized = true;
|
|
|
|
|
bool res = YoloV5Ncnn_Init(paramFile, binFile);
|
|
|
|
@ -1836,60 +1839,43 @@ bool CPhoneDevice::onBurstCapture(std::shared_ptr<ACameraMetadata> characteristi
|
|
|
|
|
pThis->TakePhotoCb(1, photoInfo, "", takingTime);
|
|
|
|
|
|
|
|
|
|
#ifdef USING_EXEC_HDRP
|
|
|
|
|
// exec()
|
|
|
|
|
{
|
|
|
|
|
uint64_t uniqueId = pThis->m_uniqueIdFeed.fetch_add(1);
|
|
|
|
|
std::string cmd = pThis->m_nativeLibraryDir;
|
|
|
|
|
if (!endsWith(cmd, DIR_SEP_STR))
|
|
|
|
|
{
|
|
|
|
|
cmd += DIR_SEP_STR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string tmpDir = pThis->m_appPath + (APP_DIR_TMP DIR_SEP_STR) + std::to_string(uniqueId) + DIR_SEP_STR;
|
|
|
|
|
EnsureDirectoryPathExists(tmpDir);
|
|
|
|
|
cmd += "libhdrp.so";
|
|
|
|
|
|
|
|
|
|
std::vector<std::vector<uint8_t> > localFrames;
|
|
|
|
|
localFrames.swap(pByteArrays.get()->byteArrays);
|
|
|
|
|
|
|
|
|
|
std::string outputPath = tmpDir + "output.tiff";
|
|
|
|
|
std::string outputPath = tmpDir + "output.bmp";
|
|
|
|
|
size_t numberOfFrames = localFrames.size();
|
|
|
|
|
size_t argc = numberOfFrames + 4;
|
|
|
|
|
char** argv = new char*[argc];
|
|
|
|
|
argv[argc - 1] = NULL;
|
|
|
|
|
argv[0] = MakeArgv(std::to_string(photoInfo.orientation));
|
|
|
|
|
argv[1] = MakeArgv(std::to_string(facing == ACAMERA_LENS_FACING_FRONT ? 1 : 0));
|
|
|
|
|
argv[2] = MakeArgv(outputPath);
|
|
|
|
|
std::vector<std::string> imagePaths;
|
|
|
|
|
for (int idx = 0; idx < localFrames.size(); idx++)
|
|
|
|
|
{
|
|
|
|
|
std::string imagePath = tmpDir + std::to_string(idx) + ".dng";
|
|
|
|
|
std::vector<uint8_t>& frame = localFrames[idx];
|
|
|
|
|
writeFile(tmpDir + std::to_string(idx) + ".dng", &frame[0], frame.size());
|
|
|
|
|
argv[3 + idx] = MakeArgv(tmpDir + std::to_string(idx) + ".dng");
|
|
|
|
|
if (writeFile(imagePath, &frame[0], frame.size()))
|
|
|
|
|
{
|
|
|
|
|
imagePaths.push_back(imagePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
localFrames.clear();
|
|
|
|
|
#if _DEBUG
|
|
|
|
|
const char* psz = cmd.c_str();
|
|
|
|
|
#endif
|
|
|
|
|
char* szCmd = MakeArgv(cmd);
|
|
|
|
|
|
|
|
|
|
int exitcode = execv(szCmd, argv);
|
|
|
|
|
for (int idx = 0; idx < numberOfFrames; idx++)
|
|
|
|
|
{
|
|
|
|
|
std::remove(argv[3 + idx]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete[] szCmd;
|
|
|
|
|
for (int idx = 0; idx < argc; idx++)
|
|
|
|
|
int exitCode = pThis->CallExecv(photoInfo.orientation, facing == ACAMERA_LENS_FACING_FRONT ? 1 : 0, outputPath, imagePaths);
|
|
|
|
|
for (auto it = imagePaths.cbegin(); it != imagePaths.cend(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (argv[idx] != NULL) delete[] argv[idx];
|
|
|
|
|
std::remove((*it).c_str());
|
|
|
|
|
}
|
|
|
|
|
delete[] argv;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (existsFile(outputPath))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
rgb = cv::imread(outputPath);
|
|
|
|
|
std::remove(outputPath.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::error_code errCode;
|
|
|
|
|
fs::remove_all(fs::path(tmpDir), errCode);
|
|
|
|
|
}
|
|
|
|
|
#else // USING_EXEC_HDRP
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_ERROR, "Start HDR CH=%u IMGID=%u", (uint32_t)photoInfo.channel, (uint32_t)photoInfo.photoId);
|
|
|
|
@ -2000,9 +1986,10 @@ bool CPhoneDevice::onBurstCapture(std::shared_ptr<ACameraMetadata> characteristi
|
|
|
|
|
mCamera = NULL;
|
|
|
|
|
|
|
|
|
|
cv::Mat rgb;
|
|
|
|
|
std::vector<std::shared_ptr<hdrplus::MemFile> > rawFiles;
|
|
|
|
|
media_status_t mstatus;
|
|
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<hdrplus::MemFile> > rawFiles;
|
|
|
|
|
|
|
|
|
|
if (photoInfo.usingRawFormat != 0)
|
|
|
|
|
{
|
|
|
|
|
for (int idx = 0; idx < frames.size(); idx++)
|
|
|
|
@ -2200,10 +2187,12 @@ bool CPhoneDevice::onBurstCapture(std::shared_ptr<ACameraMetadata> characteristi
|
|
|
|
|
|
|
|
|
|
if (photoInfo.usingRawFormat != 0)
|
|
|
|
|
{
|
|
|
|
|
#ifndef USING_EXEC_HDRP
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_ERROR, "Start HDR CH=%u IMGID=%u", (uint32_t)photoInfo.channel, (uint32_t)photoInfo.photoId);
|
|
|
|
|
hdrplus::hdrplus_pipeline pipeline;
|
|
|
|
|
pipeline.run_pipeline(rawFiles, 0, rgb);
|
|
|
|
|
rawFiles.clear();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_ERROR, "Finish HDR CH=%u IMGID=%u", (uint32_t)photoInfo.channel, (uint32_t)photoInfo.photoId);
|
|
|
|
|
|
|
|
|
@ -2267,6 +2256,38 @@ bool CPhoneDevice::onBurstCapture(std::shared_ptr<ACameraMetadata> characteristi
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CPhoneDevice::CallExecv(int rotation, int frontCamera, const std::string& outputPath, const std::vector<std::string>& images)
|
|
|
|
|
{
|
|
|
|
|
JNIEnv* env = NULL;
|
|
|
|
|
bool didAttachThread = false;
|
|
|
|
|
bool res = GetJniEnv(m_vm, &env, didAttachThread);
|
|
|
|
|
if (!res)
|
|
|
|
|
{
|
|
|
|
|
ALOGE("Failed to get JNI Env");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string pathsWithSpace;
|
|
|
|
|
for (auto it = images.cbegin(); it != images.cend(); ++it)
|
|
|
|
|
{
|
|
|
|
|
pathsWithSpace.append(*it);
|
|
|
|
|
pathsWithSpace.append(" ");
|
|
|
|
|
}
|
|
|
|
|
pathsWithSpace.pop_back();
|
|
|
|
|
|
|
|
|
|
jstring joutputPath = env->NewStringUTF(outputPath.c_str());
|
|
|
|
|
jstring jpathWithSpace = env->NewStringUTF(pathsWithSpace.c_str());
|
|
|
|
|
jint exitCode = env->CallIntMethod(m_javaService, mExecHdrplusMid, rotation, frontCamera, joutputPath, jpathWithSpace);
|
|
|
|
|
env->DeleteLocalRef(jpathWithSpace);
|
|
|
|
|
env->DeleteLocalRef(joutputPath);
|
|
|
|
|
|
|
|
|
|
if (didAttachThread)
|
|
|
|
|
{
|
|
|
|
|
m_vm->DetachCurrentThread();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return exitCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CPhoneDevice::OnImageReady(cv::Mat& mat)
|
|
|
|
|
{
|
|
|
|
|
time_t takingTime = time(NULL);
|
|
|
|
@ -3007,68 +3028,6 @@ void CPhoneDevice::UpdateSimcard(const std::string& simcard)
|
|
|
|
|
m_simcard = simcard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CPhoneDevice::ProcessRawCapture(bool result, int numberOfCaptures, const std::string& pathsJoinedByTab, bool frontCamera, int rotation, long photoId)
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::string> paths = split(pathsJoinedByTab, "\t");
|
|
|
|
|
|
|
|
|
|
if (paths.empty())
|
|
|
|
|
{
|
|
|
|
|
cv::Mat mat;
|
|
|
|
|
OnCaptureReady(true, false, mat, (unsigned long)photoId);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_ERROR, "Start Processing Raw Capture CH=%u IMGID=%u", (uint32_t)mPhotoInfo.channel, (uint32_t)mPhotoInfo.photoId);
|
|
|
|
|
|
|
|
|
|
hdrplus::hdrplus_pipeline pipeline;
|
|
|
|
|
cv::Mat mat;
|
|
|
|
|
pipeline.run_pipeline(paths, 0, mat);
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_ERROR, "Finish HDR CH=%u IMGID=%u", (uint32_t)mPhotoInfo.channel, (uint32_t)mPhotoInfo.photoId);
|
|
|
|
|
|
|
|
|
|
mat = convert16bit2_8bit_(mat.clone());
|
|
|
|
|
|
|
|
|
|
if (rotation >= 0)
|
|
|
|
|
{
|
|
|
|
|
if (rotation == 90)
|
|
|
|
|
{
|
|
|
|
|
cv::Mat tempPic;
|
|
|
|
|
cv::transpose(mat, tempPic);
|
|
|
|
|
cv::flip(tempPic, mat, 1);
|
|
|
|
|
}
|
|
|
|
|
else if (rotation == 180)
|
|
|
|
|
{
|
|
|
|
|
if (frontCamera)
|
|
|
|
|
{
|
|
|
|
|
flip(mat, mat, 0);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cv::flip(mat, mat, -1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (rotation == 270)
|
|
|
|
|
{
|
|
|
|
|
cv::Mat tempPic;
|
|
|
|
|
cv::transpose(mat, tempPic);
|
|
|
|
|
cv::flip(tempPic, mat, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_ERROR, "Finish rotation CH=%u IMGID=%u", (uint32_t)mPhotoInfo.channel, (uint32_t)mPhotoInfo.photoId);
|
|
|
|
|
}
|
|
|
|
|
cv::cvtColor(mat, mat, cv::COLOR_RGB2BGR);
|
|
|
|
|
|
|
|
|
|
XYLOG(XYLOG_SEVERITY_ERROR, "Finish Processing Raw Capture CH=%u IMGID=%u", (uint32_t)mPhotoInfo.channel, (uint32_t)mPhotoInfo.photoId);
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
// cv::cvtColor(outputImg, outputImg, cv::COLOR_RGB2BGR);
|
|
|
|
|
// cv::imwrite("/sdcard/com.xypower.mpapp/tmp/final.jpg", mat);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
OnCaptureReady(true, result != JNI_FALSE, mat, (unsigned long)photoId);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CPhoneDevice::GetIceData(IDevice::ICE_INFO *iceInfo, IDevice::ICE_TAIL *iceTail, SENSOR_PARAM *sensorParam)
|
|
|
|
|
{
|
|
|
|
|
Collect_sensor_data(); //15s
|
|
|
|
|