# Camera operation do not work

**URL:** https://discourse.vtk.org/t/camera-operation-do-not-work/4813
**Category:** Support
**Created:** [December 12, 2020, 7:34am UTC](https://discourse.vtk.org/t/camera-operation-do-not-work/4813 "2020-12-12T07:34:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [December 12, 2020, 7:34am UTC](https://discourse.vtk.org/t/camera-operation-do-not-work/4813/1 "2020-12-12T07:34:26Z")

</div>

Now, I display a 2D image by the following code:

```auto
import vtk

img = vtk.vtkDICOMImageReader()
img.SetFileName('C:\\Users\\MLoong\\Desktop\\dicom_data\\Chang Cheng\\TOF\\IM_0174')
img.Update()

mapper = vtk.vtkImageMapper()
mapper.SetInputData(img.GetOutput())
actor = vtk.vtkActor2D()
actor.SetMapper(mapper)

ren = vtk.vtkRenderer()
ren.AddActor(actor)
ren.SetBackground(0.1, 0.2, 0.4)

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(400, 400)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

renWin.Render()
# iren.Start()

print(ren.GetActiveCamera().GetPosition())

# ren.GetActiveCamera().SetPosition([0, 0, 0.5]) ############ change the camera position
# ren.ResetCameraClippingRange()
# ren.UpdateLightsGeometryToFollowCamera()
renWin.Render()
iren.Start()

```

I print the camera position by `print(ren.GetActiveCamera().GetPosition())`, and the position is [0, 0, 1].

And the result is:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/5/5d2172c2d8feccf3d3bb672ba3866a52d411ff3a.jpeg)

Now, I want to change the camera position by:

```auto
...
print(ren.GetActiveCamera().GetPosition())
ren.GetActiveCamera().SetPosition([0, 0, 0.5])
ren.ResetCameraClippingRange()
ren.UpdateLightsGeometryToFollowCamera()
...

```

In my understanding, the camera is moved toward the object. Thus, the image should be zoom in. However, there is no change, and the result is:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/5/5ef0c6311cecbfaf247a10457cc438d7cad768ba.jpeg)

What’s wrong with my code? Any suggestion is appreciated!

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [December 13, 2020, 1:30pm UTC](https://discourse.vtk.org/t/camera-operation-do-not-work/4813/2 "2020-12-13T13:30:18Z")

</div>

Hi, Zhang,

Can you, please, change your code to this:

> [@](#):
>
> `ren.GetActiveCamera().SetPosition([1, 1, 0.5])`

?

Does it have an effect?

regards,

Paulo

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [December 13, 2020, 1:53pm UTC](https://discourse.vtk.org/t/camera-operation-do-not-work/4813/3 "2020-12-13T13:53:48Z")

</div>

Thank you for your reply. But `ren.GetActiveCamera().SetPosition([1, 1, 0.5])` has no effect on the final result. So confuzed~~~

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [December 13, 2020, 8:33pm UTC](https://discourse.vtk.org/t/camera-operation-do-not-work/4813/4 "2020-12-13T20:33:35Z")

</div>

Can you try translating the focal point by the same delta x and delta y in addition to setting position? e.g. `SetFocalPoint (1, 1, 0.0)`

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [December 14, 2020, 12:48am UTC](https://discourse.vtk.org/t/camera-operation-do-not-work/4813/5 "2020-12-14T00:48:14Z")

</div>

> [@Paulo\_Carvalho](#):
>
> `SetFocalPoint (1, 1, 0.0)`

I modify the code as:

```auto

ren.GetActiveCamera().SetPosition([0, 0, 0.5]) ############ change the camera position
ren.GetActiveCamera().SetFocalPoint ([10, 10, 0.0])

```

And the result is:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/e/e79968c9383b0032ae053cf6a87dbb6fb9ef3ed3.jpeg)

I think there is no change.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [December 15, 2020, 1:57pm UTC](https://discourse.vtk.org/t/camera-operation-do-not-work/4813/6 "2020-12-15T13:57:01Z")

</div>

Hello,

Please, take a look at this example: [https://vtk.org/Wiki/VTK/Examples/Cxx/Images/InteractWithImage](https://vtk.org/Wiki/VTK/Examples/Cxx/Images/InteractWithImage) . It features the operations on a 2D image you are trying like pan and zoom.

regards,

Paulo
