Open cv on tx2 won’t work with onboard csi camera

I have Ubuntu 16.04
I built Opencv 3.3 with gstreamer support
USB cameras works
And I am able to open the csi camera successfully from terminal

But when I use this pipeline in my opencv program:

VideoCapture(
nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink);

my program builds and when I run it from the build folder using ./my program
I get no errors but, nothing happens and no camera open.
Am I doing something wrong?
Please help.

You may try this:

import cv2
print(cv2.__version__)

cap = cv2.VideoCapture('nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480,format=(string)I420, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink')

while(True):
	ret, frame = cap.read();
	cv2.imshow('MyFrame', frame)
	if cv2.waitKey(1) & 0xFF == ord('q'):
		break