增加云台摄像机的拍照处理

N938
Matthew 6 months ago
parent 9facbf3c55
commit eebf9b5a03

@ -514,7 +514,24 @@ public:
PowerControl(CMD_SET_OTG_STATE, CMD_SET_NETWORK_POWER_EN, CMD_SET_PIC1_POWER, CMD_SET_485_EN_STATE, closeDelayTime)
#else // USING_N938
#ifdef USING_PLZ
PowerControl(CMD_SET_PTZ_PWR_ENABLE, CMD_SET_100M_ENABLE, CMD_SET_100M_SWITCH_PWR_ENABLE, CMD_SET_12V_EN_STATE, closeDelayTime)
PowerControl(CMD_SET_OTG_STATE, CMD_SET_100M_ENABLE, CMD_SET_100M_SWITCH_PWR_ENABLE, CMD_SET_12V_EN_STATE, closeDelayTime)
#else // USING_PLZ
PowerControl(CMD_SET_OTG_STATE, CMD_SET_12V_EN_STATE, closeDelayTime)
#endif // USING_PLZ
#endif // USING_N938
{
}
};
class PlzCameraPowerCtrl : public PowerControl
{
public:
PlzCameraPowerCtrl(uint32_t closeDelayTime) :
#ifdef USING_N938
PowerControl(CMD_SET_OTG_STATE, CMD_SET_NETWORK_POWER_EN, CMD_SET_PIC1_POWER, CMD_SET_485_EN_STATE, closeDelayTime)
#else // USING_N938
#ifdef USING_PLZ
PowerControl(CMD_SET_OTG_STATE, CMD_SET_PTZ_PWR_ENABLE, CMD_SET_100M_ENABLE, CMD_SET_100M_SWITCH_PWR_ENABLE, CMD_SET_12V_EN_STATE, closeDelayTime)
#else // USING_PLZ
PowerControl(CMD_SET_OTG_STATE, CMD_SET_12V_EN_STATE, closeDelayTime)
#endif // USING_PLZ

@ -1482,6 +1482,145 @@ IDevice::timer_uid_t CPhoneDevice::RegisterHeartbeat(unsigned int timerType, uns
return uid;
}
bool CPhoneDevice::TakePhotoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, const std::string& path, std::vector<IDevice::OSD_INFO>& osds, std::shared_ptr<PowerControl> powerCtrlPtr)
{
// AutoEnv autoEnv(pThis->m_vm);
time_t ts = time(NULL);
uint32_t waitTime = localPhotoInfo.selfTestingTime;
waitTime = (waitTime!= 0) ? (waitTime * 1024) : 10240;
std::this_thread::sleep_for(std::chrono::milliseconds(waitTime));
SetStaticIp();
std::this_thread::sleep_for(std::chrono::milliseconds(256));
net_handle_t netHandle = GetNetHandle();
if (netHandle == 0)
{
// Wait about 10s
for (int idx = 0; idx < 84; idx++)
{
std::this_thread::sleep_for(std::chrono::milliseconds(128));
netHandle = GetNetHandle();
if (netHandle != 0)
{
break;
}
}
}
if (netHandle == 0)
{
// timeout
XYLOG(XYLOG_SEVERITY_ERROR, "Ethernet not existing CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset, localPhotoInfo.photoId);
TakePhotoCb(0, localPhotoInfo, "", 0);
return false;
}
else
{
XYLOG(XYLOG_SEVERITY_INFO, "Ethernet is Available CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset, localPhotoInfo.photoId);
}
NET_PHOTO_INFO netPhotoInfo = { netHandle, 0 };
if (localPhotoInfo.vendor == 1)
{
// Hai Kang
netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST;
snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/ISAPI/Streaming/channels/%u/picture", (uint32_t)localPhotoInfo.channel);
}
else if (localPhotoInfo.vendor == 2)
{
// Hang Yu
strcpy(netPhotoInfo.url, "/cgi-bin/snapshot.cgi");
}
else if (localPhotoInfo.vendor == 3)
{
// Yu Shi
netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST;
int streamSid = 0; // should put into config
snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/LAPI/V1.0/Channels/%u/Media/Video/Streams/%d/Snapshot", (uint32_t)localPhotoInfo.channel, streamSid);
}
else if (localPhotoInfo.vendor == 5)
{
// Hang Yu - New
netPhotoInfo.authType = HTTP_AUTH_TYPE_BASIC;
// http://192.168.1.46/Snapshot/%u/RemoteImageCapture?ImageFormat=2&HorizontalPixel=1920&VerticalPixel=1080
// http://192.168.1.101/Snapshot/1/2/RemoteImageCaptureV2?ImageFormat=jpg
// http://192.168.1.101/Snapshot/1/1/RemoteImageCaptureV2?ImageFormat=jpg
snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/Snapshot/%u/1/RemoteImageCaptureV2?ImageFormat=jpg", (uint32_t)localPhotoInfo.channel);
}
else
{
XYLOG(XYLOG_SEVERITY_ERROR, "Vendor(%u) not Supported CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.vendor, (uint32_t)localPhotoInfo.channel, (unsigned int)localPhotoInfo.preset, localPhotoInfo.photoId);
TakePhotoCb(0, localPhotoInfo, "", 0);
return false;
}
struct in_addr addr;
addr.s_addr = localPhotoInfo.ip;
strcpy(netPhotoInfo.ip, inet_ntoa(addr));
strcpy(netPhotoInfo.outputPath, path.c_str());
if (!localPhotoInfo.userName.empty())
{
size_t len = std::min<size_t>(sizeof(netPhotoInfo.userName) - 1, localPhotoInfo.userName.size());
strncpy(netPhotoInfo.userName, localPhotoInfo.userName.c_str(), len);
}
if (!localPhotoInfo.password.empty())
{
size_t len = std::min<size_t>(sizeof(netPhotoInfo.password) - 1, localPhotoInfo.password.size());
strncpy(netPhotoInfo.password, localPhotoInfo.password.c_str(), len);
}
// strcpy(netPhotoInfo.interface, "eth0");
std::vector<uint8_t> img;
bool netCaptureResult = false;
for (int idx = 0; idx < 3; idx++)
{
netHandle = GetNetHandle();
netPhotoInfo.netHandle = netHandle;
XYLOG(XYLOG_SEVERITY_INFO, "NetCapture %d NetHandle=%lld PHOTOID=%u", idx, netHandle, localPhotoInfo.photoId);
netCaptureResult = requestCapture(localPhotoInfo.channel, localPhotoInfo.preset, netPhotoInfo, img);
if (netCaptureResult)
{
break;
}
}
if (netCaptureResult)
{
time_t takingTime = ts;
if (localPhotoInfo.remedy != 0)
{
if ((takingTime - localPhotoInfo.scheduleTime) > 30)
{
takingTime = localPhotoInfo.scheduleTime + localPhotoInfo.channel * 2;
}
}
localPhotoInfo.photoTime = takingTime;
// Notify to take next photo
TakePhotoCb(1, localPhotoInfo, "", takingTime);
cv::Mat rgb = cv::imdecode(cv::Mat(img), cv::IMREAD_COLOR);
#ifdef _DEBUG
// cv::imwrite("/sdcard/com.xypower.mpapp/tmp/netimg2.jpg", rgb);
#endif
netCaptureResult = PostProcessPhoto(localPhotoInfo, osds, path, "", rgb);
}
else
{
XYLOG(XYLOG_SEVERITY_ERROR, "Faile to TP on NET Camera CH=%u PR=%X PHOTOID=%u URL=http://%s%s", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset,
localPhotoInfo.photoId, netPhotoInfo.ip, netPhotoInfo.url);
TakePhotoCb(0, localPhotoInfo, "", 0);
}
return true;
}
bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<OSD_INFO>& osds, const std::string& path)
{
if (photoInfo.width == 0 || photoInfo.height == 0)
@ -1544,6 +1683,10 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
{
powerCtrlPtr = std::shared_ptr<PowerControl>(new NetCameraPowerCtrl(mPhotoInfo.closeDelayTime));
}
else if (photoInfo.cameraType == CAM_TYPE_PLZ)
{
powerCtrlPtr = std::shared_ptr<PowerControl>(new PlzCameraPowerCtrl(mPhotoInfo.closeDelayTime));
}
res = true;
if ((mPhotoInfo.mediaType == 0) && ((mPhotoInfo.cameraType == CAM_TYPE_MIPI) || (mPhotoInfo.cameraType == CAM_TYPE_USB)))
@ -1638,139 +1781,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
std::thread t([localPhotoInfo, path, pThis, osds, powerCtrlPtr]() mutable
{
// AutoEnv autoEnv(pThis->m_vm);
time_t ts = time(NULL);
uint32_t waitTime = localPhotoInfo.selfTestingTime;
waitTime = (waitTime!= 0) ? (waitTime * 1024) : 10240;
std::this_thread::sleep_for(std::chrono::milliseconds(waitTime));
pThis->SetStaticIp();
std::this_thread::sleep_for(std::chrono::milliseconds(256));
net_handle_t netHandle = pThis->GetNetHandle();
if (netHandle == 0)
{
// Wait about 10s
for (int idx = 0; idx < 84; idx++)
{
std::this_thread::sleep_for(std::chrono::milliseconds(128));
netHandle = pThis->GetNetHandle();
if (netHandle != 0)
{
break;
}
}
}
if (netHandle == 0)
{
// timeout
XYLOG(XYLOG_SEVERITY_ERROR, "Ethernet not existing CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset, localPhotoInfo.photoId);
pThis->TakePhotoCb(0, localPhotoInfo, "", 0);
return;
}
else
{
XYLOG(XYLOG_SEVERITY_INFO, "Ethernet is Available CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset, localPhotoInfo.photoId);
}
NET_PHOTO_INFO netPhotoInfo = { netHandle, 0 };
if (localPhotoInfo.vendor == 1)
{
// Hai Kang
netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST;
snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/ISAPI/Streaming/channels/%u/picture", (uint32_t)localPhotoInfo.channel);
}
else if (localPhotoInfo.vendor == 2)
{
// Hang Yu
strcpy(netPhotoInfo.url, "/cgi-bin/snapshot.cgi");
}
else if (localPhotoInfo.vendor == 3)
{
// Yu Shi
netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST;
int streamSid = 0; // should put into config
snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/LAPI/V1.0/Channels/%u/Media/Video/Streams/%d/Snapshot", (uint32_t)localPhotoInfo.channel, streamSid);
}
else if (localPhotoInfo.vendor == 5)
{
// Hang Yu - New
netPhotoInfo.authType = HTTP_AUTH_TYPE_BASIC;
// http://192.168.1.46/Snapshot/%u/RemoteImageCapture?ImageFormat=2&HorizontalPixel=1920&VerticalPixel=1080
// http://192.168.1.101/Snapshot/1/2/RemoteImageCaptureV2?ImageFormat=jpg
// http://192.168.1.101/Snapshot/1/1/RemoteImageCaptureV2?ImageFormat=jpg
snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/Snapshot/%u/1/RemoteImageCaptureV2?ImageFormat=jpg", (uint32_t)localPhotoInfo.channel);
}
else
{
XYLOG(XYLOG_SEVERITY_ERROR, "Vendor(%u) not Supported CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.vendor, (uint32_t)localPhotoInfo.channel, (unsigned int)localPhotoInfo.preset, localPhotoInfo.photoId);
pThis->TakePhotoCb(0, localPhotoInfo, "", 0);
return;
}
struct in_addr addr;
addr.s_addr = localPhotoInfo.ip;
strcpy(netPhotoInfo.ip, inet_ntoa(addr));
strcpy(netPhotoInfo.outputPath, path.c_str());
if (!localPhotoInfo.userName.empty())
{
size_t len = std::min<size_t>(sizeof(netPhotoInfo.userName) - 1, localPhotoInfo.userName.size());
strncpy(netPhotoInfo.userName, localPhotoInfo.userName.c_str(), len);
}
if (!localPhotoInfo.password.empty())
{
size_t len = std::min<size_t>(sizeof(netPhotoInfo.password) - 1, localPhotoInfo.password.size());
strncpy(netPhotoInfo.password, localPhotoInfo.password.c_str(), len);
}
// strcpy(netPhotoInfo.interface, "eth0");
std::vector<uint8_t> img;
bool netCaptureResult = false;
for (int idx = 0; idx < 3; idx++)
{
netHandle = pThis->GetNetHandle();
netPhotoInfo.netHandle = netHandle;
XYLOG(XYLOG_SEVERITY_INFO, "NetCapture %d NetHandle=%lld PHOTOID=%u", idx, netHandle, localPhotoInfo.photoId);
netCaptureResult = requestCapture(localPhotoInfo.channel, localPhotoInfo.preset, netPhotoInfo, img);
if (netCaptureResult)
{
break;
}
}
if (netCaptureResult)
{
time_t takingTime = ts;
if (localPhotoInfo.remedy != 0)
{
if ((takingTime - localPhotoInfo.scheduleTime) > 30)
{
takingTime = localPhotoInfo.scheduleTime + localPhotoInfo.channel * 2;
}
}
localPhotoInfo.photoTime = takingTime;
// Notify to take next photo
pThis->TakePhotoCb(1, localPhotoInfo, "", takingTime);
cv::Mat rgb = cv::imdecode(cv::Mat(img), cv::IMREAD_COLOR);
#ifdef _DEBUG
// cv::imwrite("/sdcard/com.xypower.mpapp/tmp/netimg2.jpg", rgb);
#endif
netCaptureResult = pThis->PostProcessPhoto(localPhotoInfo, osds, path, "", rgb);
}
else
{
XYLOG(XYLOG_SEVERITY_ERROR, "Faile to TP on NET Camera CH=%u PR=%X PHOTOID=%u URL=http://%s%s", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset,
localPhotoInfo.photoId, netPhotoInfo.ip, netPhotoInfo.url);
pThis->TakePhotoCb(0, localPhotoInfo, "", 0);
}
pThis->TakePhotoWithNetCamera(localPhotoInfo, path, osds, powerCtrlPtr);
});
t.detach();
@ -1837,6 +1848,34 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
t.detach();
}
else if (mPhotoInfo.mediaType == 0 && (mPhotoInfo.cameraType == CAM_TYPE_PLZ))
{
uint64_t wid_serial = RequestWakelock(0);
CPhoneDevice* pThis = this;
IDevice::PHOTO_INFO localPhotoInfo = mPhotoInfo;
IDevice::SerialsPhotoParam param = { "", 0, 0 };
GetPhotoSerialsParamCb(param);
vector<IDevice::OSD_INFO> osds;
osds.swap(mOsds);
std::thread t([localPhotoInfo, param, pThis, path, osds, wid_serial, powerCtrlPtr]() mutable
{
time_t ts = time(NULL);
pThis->OpenPTZSensors(localPhotoInfo.selfTestingTime);
if (localPhotoInfo.preset != 0 && localPhotoInfo.preset != 0xFF)
{
XYLOG(XYLOG_SEVERITY_INFO,"Recv CameraCtrl Command, action= MOVE_PRESETNO, preset = %u", localPhotoInfo.preset);
CameraPhotoCmd(time(NULL), localPhotoInfo.channel, MOVE_PRESETNO, 0, localPhotoInfo.preset, param.serfile, param.baud, param.addr);
std::this_thread::sleep_for(std::chrono::seconds(5));
}
pThis->TakePhotoWithNetCamera(localPhotoInfo, path, osds, powerCtrlPtr);
pThis->ReleaseWakelock(wid_serial);
});
t.detach();
}
else if (mPhotoInfo.usingSysCamera == 1)
{
JNIEnv* env = NULL;

@ -272,6 +272,7 @@ protected:
bool SendBroadcastMessage(std::string action, int value);
// bool MatchCaptureSizeRequest(ACameraManager *cameraManager, const char *selectedCameraId, unsigned int width, unsigned int height, uint32_t cameraOrientation_,
bool TakePhotoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, const std::string& path, std::vector<IDevice::OSD_INFO>& osds, std::shared_ptr<PowerControl> powerCtrlPtr);
bool PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector<IDevice::OSD_INFO>& osds, const std::string& path, const std::string& cameraInfo, cv::Mat& mat);
inline bool TakePhotoCb(int res, const IDevice::PHOTO_INFO& photoInfo, const string& path, time_t photoTime, const std::vector<IDevice::RECOG_OBJECT>& objects) const
{

Loading…
Cancel
Save