Video zooming direction control issue

At present, if I use the mouse wheel to zoom in on the video, I can use the arrow key function to control the current zoomed position, but if I use the mouse to hold down the left button and drag to zoom in, it seems like I can’t read its zoom value or control it, resulting in that when I use the arrow keys to control, it will jump back to the starting position, how can I fix it?

(issue video link: https://youtu.be/x7n92WHvyuM)

※Here is how I use Milestone SDK to zooming with mouse wheel:

//ZoomIn

VideoOS.Platform.Messaging.Message msg = new VideoOS.Platform.Messaging.Message(

            MessageId.Control.PTZMoveCommand,

            VideoOS.Platform.Messaging.PTZMoveCommandData.ZoomIn);

EnvironmentManager.Instance.PostMessage(msg, ImageViewWpf1.CameraFQID);

※Here is how I read the value of the zooming:

ImageViewWpf1.EnableDigitalZoom = true;

if (e.Delta > 0)

{

//ZoomIn

if (zoom + zoomlayer < 1000)

{

zoom += zoomlayer;

ImageViewWpf1.PtzCenter(80, 100, x, y, zoom);

}

}

※Here is how I use Milestone SDK to use the arrow key function to control the current zoomed position:

//LeftClick

VideoOS.Platform.Messaging.Message msg = new VideoOS.Platform.Messaging.Message(

            MessageId.Control.PTZMoveCommand,

            VideoOS.Platform.Messaging.PTZMoveCommandData.Left);

EnvironmentManager.Instance.SendMessage(msg, ImageViewWpf1.CameraFQID);

When testing I find that PTZMoveCommand has no effect on a digitally zoomed view in ImageViewerWpfControl.

ImageViewerWpfControl.PtzCenter() is the only method that works on the digitally zooming, but it works only for setting the digital zoom not for reading.

There is no method for reading zoom or location of digital zoom, only PtzCenter for setting it.

With these findings I do not see any solution to unify the control by code which is possible with the PtzCenter method with control by use of the direct drag to zoom in the ImageViewerWpfControl UI.

-

Are you using the newest MIP SDK, 2022R2 version? Is there anything I am missing in my test?

Thanks for the Correction and Sorry for the wrong input there. But we are using PTZMoveCommand for PTZ camera and PTZCenter for normal camera as you could see bellow

//LeftClick

private void LeftPTZ_Click(object sender, RoutedEventArgs e)

{

  //check if this one was PTZ camera

  if (Camera\_Name.Substring(0, 2).Equals("PC"))

  {

    VideoOS.Platform.Messaging.Message msg = new VideoOS.Platform.Messaging.Message(

                    MessageId.Control.PTZMoveCommand,

                    VideoOS.Platform.Messaging.PTZMoveCommandData.Left);

    EnvironmentManager.Instance.SendMessage(msg, ImageViewWpf1.CameraFQID);

  }

  else //check if this one was normal camera

  {

    ImageViewWpf1.EnableDigitalZoom = true;

    if (x - 1 > (int)((80 \* (zoom / 1000)) / 2))

    {

      x -= 1;

      ImageViewWpf1.PtzCenter(80, 100, x, y, zoom);

    }

  }

}

Could you give us any insight or algorithm how to set the PTZCenter , Width,Height,X,Y,and zoom when we use drag to zoom and select arrow to move it .

Thanks alot in advice.​

Please see the documentation

--

void VideoOS.Platform.Client.ImageViewerWpfControl.PtzCenter (int refWidth, int refHeight, int centerX, int centerY, int zoom) inline

-

Perform PTZ Center in the current mode. Either Digital zoom, PanoramicLens (Fisheye), or physical camera move.

The zoom parameter can be -1 for no change, or a range from 0..1000, where 0 will zoom out completely. The other values are can be in any size and does not relate to the real resolution of the image.

_imageViewerControl1.PtzCenter(100, 100, 25, 50, 500); Will zoom 50% and center around a point (25,50) to the left hand side of the image.

--

Ref. https://doc.developer.milestonesys.com/html/index.html?base=miphelp/class_video_o_s_1_1_platform_1_1_client_1_1_image_viewer_wpf_control.html&tree=tree_search.html?search=ptzcenter

What makes it not straightforward to use is that you use center for locating the rectangle of zoomed area, and if then touching the border it will put the rectangle differently. Also, the behavior is slightly different depending whether you use MaintainImageRatio, when true the control will introduce black border in order not to stretch the image, when false the image is stretched to fill the control area.

There is unfortunately no code in the samples on how to convert from a rectangle on screen to a set of PtzCenter parameters.

Your question made me think, and I realized that parts of the code could be reused form the VideoPreview plugin sample. I added a cjeck box to the ImageViewer sample, and now the code below works for me on non-ptz cameras.

private void _ptzCenter_Click(object sender, RoutedEventArgs e)
{            
		_PTZCenterMode = _doPtzCenter.IsChecked ?? false;
}
 
private void IVC_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
	if (_PTZCenterMode)
	{
		_first = e.GetPosition(_imageViewerControl);
	}
}
 
private void IVC_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
	if (_PTZCenterMode)
	{
		_next = e.GetPosition(_imageViewerControl);
		DoCenter();
	}
}
 
private void DoCenter()
{
	Point firstPoint = TransformRatio(_first, _imageViewerControl.PaintSize, _imageViewerControl.RenderSize);
	Point nextPoint = TransformRatio(_next, _imageViewerControl.PaintSize, _imageViewerControl.RenderSize);
	_digitalZoomCheckBox.IsChecked = true;
	_imageViewerControl.EnableDigitalZoom = true;
	int zoom = Convert.ToInt32(1000 * ((_imageViewerControl.RenderSize.Width - Math.Abs(firstPoint.X - nextPoint.X)) / _imageViewerControl.RenderSize.Width));
	int zoomy = Convert.ToInt32(1000 * ((_imageViewerControl.RenderSize.Height - Math.Abs(firstPoint.Y - nextPoint.Y)) / _imageViewerControl.RenderSize.Height));
	zoom = Math.Min(zoom, zoomy);
	int xval = Convert.ToInt32((firstPoint.X + nextPoint.X) / 2);
	int yval = Convert.ToInt32((firstPoint.Y + nextPoint.Y) / 2);
 
	_imageViewerControl.PtzCenter(
		(int)_imageViewerControl.PaintSize.Width,
		(int)_imageViewerControl.PaintSize.Height,
		xval,
		yval,
		zoom
		);
}
 
private Point TransformRatio(Point point, Size paintSize, Size renderSize)
{
	var leftMargin = (renderSize.Width - paintSize.Width) / 2;
	point.X -= leftMargin;
	var topMargin = (renderSize.Height - paintSize.Height) / 2;
	point.Y -= topMargin;
	return point;
}

Let me know if it works for you.