Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixel coords #7

Open
wants to merge 7 commits into
base: image_masking
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 66 additions & 2 deletions RobotTesting/Assets/Scripts/CameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,27 @@
public class CameraController : MonoBehaviour{

public bool MaskOn;
//Bool set in inspector to control if camera is masker or main

public Shader ReplacShaderWhite;

//Shader with Ids used to replace robot and marker selectively

public GameObject ToolTipObj;
//Small sphere on end of tooltip that is used to track tooltip

private Vector4 _toolTipPosn;
JaredMohansingh marked this conversation as resolved.
Show resolved Hide resolved
//value for theposition of the tooltip

private Matrix4x4 _camIntr;
//camera projection matrix (intrinsics)

private Vector3 _screenCoords ;
JaredMohansingh marked this conversation as resolved.
Show resolved Hide resolved
//answer matrix (pixel coords of image)

private Matrix4x4 _camToWorld ;
JaredMohansingh marked this conversation as resolved.
Show resolved Hide resolved
//camera extrinsics

private long _fileLength;
private int _imageNumber;
private Texture2D _camView;
private Camera _overHeadCam;
Expand All @@ -29,6 +48,14 @@ void GetCamView(){
//If the tick box is selected in the inspector, then the path is changed accordingly
if(MaskOn) {
File.WriteAllBytes( "MaskedImages/MaskedImage" + _imageNumber + ".jpg" , bytes );

if ( ToolTipVisible() ) {
Debug.Log("TOOL TIP IS VISIBLE");
JaredMohansingh marked this conversation as resolved.
Show resolved Hide resolved
GetCoords();
} else {
Debug.Log("TOOL TIP IS BLOCKED");
System.IO.File.AppendAllText( @"coords.txt" , "null , null" + "\n" );
}
} else {
File.WriteAllBytes( "Images/Image" + _imageNumber + ".jpg" , bytes );
}
Expand All @@ -38,7 +65,14 @@ void GetCamView(){

private void Start(){
_overHeadCam = GetComponent<Camera>();


_camIntr[0,0] = 3464.10161514f;
_camIntr[0,2] = 2000.0f;
_camIntr[1,1] = 3464.10161514f;
_camIntr[1,2] = 2000.0f;
_camIntr[2,2] = 1.0f;
//Sets uep the camera intrinsics matrix
JaredMohansingh marked this conversation as resolved.
Show resolved Hide resolved

//If the tick box is selected in the inspector, the replacement shader is loaded for cam
if (MaskOn)
{
Expand All @@ -50,4 +84,34 @@ private void Start(){
InvokeRepeating("GetCamView",1.5f,3.0f);
}

private void GetCoords(){
_toolTipPosn = ToolTipObj.transform.position ;
//Reads the position of the TCP

_toolTipPosn[3] = 1.0f;
//This is needed to set the 1 in the W component of the vector as it is reset every time the
//previous line is executed

_camToWorld = _overHeadCam.worldToCameraMatrix ;
//Sets the matrix that transforms the world space to camera space

_screenCoords = _camIntr * _camToWorld * _toolTipPosn;
//Camera calibration calulation
JaredMohansingh marked this conversation as resolved.
Show resolved Hide resolved

//Debug.Log( _screenCoords[0]/ _screenCoords[2] + " and " + _screenCoords[1]/ _screenCoords[2] );
JaredMohansingh marked this conversation as resolved.
Show resolved Hide resolved

System.IO.File.AppendAllText( @"coords.txt" , _screenCoords[0]/ _screenCoords[2] + " , "
+ _screenCoords[1]/ _screenCoords[2] + "\n" );
//Writes the coordinates to a txt file
}

private bool ToolTipVisible() {
_fileLength = new System.IO.FileInfo("MaskedImages/MaskedImage" + _imageNumber + ".jpg").Length;
if ( _fileLength > 250628 ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will this work if you have two cameras with different image sizes (highly probable)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, we'll only be using one camera. Add a TODO to update this to be more robust to deal with multiple cameras instead.

return true;
}
else {
return false;
}
}
}
JaredMohansingh marked this conversation as resolved.
Show resolved Hide resolved
Loading