Logic Machine Forum
LM object data as metadata on videocamera's stream - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: LM object data as metadata on videocamera's stream (/showthread.php?tid=1813)



LM object data as metadata on videocamera's stream - AlexLV - 27.12.2018

Hi [Image: smile.png]

Please help me adapt script from other system to LM. In result we will see any object data on videostream (Works with Hikvision cameras). In simple words - if we open videocamera videostream on it we will see our data. I use Hikvision camera and now when I connect to it remotely using Hikvision videosoftware I see outside temperature and my heating device temperature. . etc..

How it works on my other system - at C:/ disk (win10) located 1.xml file. In 1.xml file also located coordinates in pixel where our data will be shown at videostream (from upper left corner - X and Y position of starting place for our text).. I insert values I need to show at my camera videostream to this 1.xml file. After that with curl.exe it sends to camera. This repeated every minute (Just cycle how often we want to update values at videostream..).

So, questions:
1. how put on LM SD card 1.xml file and later put data in 1.xml using script???
2. how execute curl command and use it with string in script above?



My script on other system:

$CONNSTRING = "http://camera_loginandpass@cameraIP/Video/inputs/channels/1/overlays/text/";
$value=getGlobal('Mainsity.Today_temp'); -- in our case we take LM's needed object's value and put it in 1.xml

file_put_contents('C:\1.xml', $xml);
exec('C:\curl.exe -T C:\1.xml '.$CONNSTRING.'1');
//$answer=exec('C:\curl.exe -T C:\1.xml '.$CONNSTRING.'1'); 
//echo $answer;


Alex


RE: LM object data as metadata on videocamera's stream - admin - 27.12.2018

Post XML file contents. There's no need to save file anywhere as you can send data directly from the script using LuaSocket. I'll post an example bit later.


RE: LM object data as metadata on videocamera's stream - AlexLV - 27.12.2018

1.xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<TextOverlay xmlns="http://www.hikvision.com/ver10/XMLSchema" version="1.0">
<id>1</id>
<enabled>true</enabled>
<posX>16</posX>
<posY>16</posY>
<message>$value</message>
</TextOverlay>


RE: LM object data as metadata on videocamera's stream - admin - 27.12.2018

Try this, change camera URL and text message as needed. Uncomment last line with logging if request does not work.
Code:
url = 'http://USER:PASS@IP/Video/inputs/channels/1/overlays/text/1'
text = 'Test message'

function http_put_xml(url, xml)
  local http = require('socket.http')
  local ltn12 = require('ltn12')
  local resp = {}

  local res, code = http.request({
    url = url,
    method = 'PUT',
    headers = {
      ['content-type'] = 'text/xml',
      ['content-length'] = #xml,
    },
    source = ltn12.source.string(xml),
    sink = ltn12.sink.table(resp),
  })

  if res then
    return table.concat(resp), code
  else
    return nil, code
  end
end

function xml_escape(text)
  return text
    :gsub('&', '&amp;')
    :gsub('<', '&lt;')
    :gsub('>', '&gt;')
    :gsub('"', '&quot;')
    :gsub("'", '&apos;')
end

xml = [[<?xml version="1.0" encoding="UTF-8"?>
<TextOverlay xmlns="http://www.hikvision.com/ver10/XMLSchema" version="1.0">
<id>1</id>
<enabled>true</enabled>
<posX>16</posX>
<posY>16</posY>
<message>]] .. xml_escape(text) .. [[</message>
</TextOverlay>]]

res, err = http_put_xml(url, xml)
-- log(res, err)



RE: LM object data as metadata on videocamera's stream - AlexLV - 27.12.2018

[quote pid='11307' dateline='1545918376']
Admin, 
BIG THANKS Smile 
All works. 

Result seen in attachment..



[/quote]


RE: LM object data as metadata on videocamera's stream - rogerabit - 14.01.2019

Hi,
I have a ip cameras with an stream MJPEG. The url to acces to cam is: http://user:pwd@Ip_Adress/Streaming/channels/102/httpPreview
If I open de url in the web browser it's opening without problem, but if I configure a camera button in a visualitzation of LM, the camera not open.
WHY?
Can you help me?


RE: LM object data as metadata on videocamera's stream - Daniel - 14.01.2019

Hi
Yo need direct url stream, try to find it here https://www.ispyconnect.com/sources.aspx
BR


RE: LM object data as metadata on videocamera's stream - admin - 14.01.2019

You need to disable username/password or pass them as URL parameters (if camera supports it). This is a security limitation in most modern browsers, there's nothing we can do from our side.


RE: LM object data as metadata on videocamera's stream - rogerabit - 14.01.2019

Hi.
I have a direct url stream, and in the url i put the user and pwd.
I open the camera button and appear this:

[Image: camera-error.jpg]
but if I click in broken image with de right button and choose copy image url (Copiar dirección de la imagen) i can view the ip camera in a window of chrome.
[Image: camera-error2.jpg]


RE: LM object data as metadata on videocamera's stream - AlexLV - 16.01.2019

For me it works in Mozilla not in Chrome. Test with Firefox.
As mentioned ONLY new Hik cameras allow disable user autentification. My cam is old enough and not allow do such things.
Also try to find newest firmware for Hik cam here:
http://www.hikvisioneurope.com/portal/?dir=portal/Product%20Firmware%202018/Front-ends

(Please note Hik divide cameras by platforms, so check which is yours, or just write to me in PM)
Alex


RE: LM object data as metadata on videocamera's stream - rogerabit - 17.01.2019

(16.01.2019, 19:09)AlexLV Wrote: For me it works in Mozilla not in Chrome. Test with Firefox.
As mentioned ONLY new Hik cameras allow disable user autentification. My cam is old enough and not allow do such things.
Also try to find newest firmware for Hik cam here:
http://www.hikvisioneurope.com/portal/?dir=portal/Product%20Firmware%202018/Front-ends

(Please note Hik divide cameras by platforms, so check which is yours, or just write to me in PM)
Alex

Thanks AlexLV! With Firefox it works!
Thanks