Ask Your Question

Revision history [back]

Issue while running OpenCv Python script on Amazon-Ec2 Instance

I am calling a Python script using php System() function.

Python script implements the Foreground subtraction using OpenCv library. I upload the image using Post request and then pass the file to the script.

Following things are getting executed in the code

1. Uploading file through Post request.
2. Passing the file to Python Script
3. Script reads the file, implements the 
   Foreground subtraction algorithm    
   and saves this to a new file.

I am Testing this program using two images, 1500 * 701 pixels and 2368 * 4208 pixels.

Everything is working fine for the low resolution image. But for the high resolution image, Python script keeps exiting.

Php code.

system("python /var/www/html/wowflux/public/scripts/test.py",$ret_val);
var_dump($ret_val);

Python script

import numpy as np
import cv2
import math
import os 
import sys
from sys import path
from matplotlib import pyplot as plt

##test_image = cv2.imread(sys.argv[1])
test_image = cv2.imread("/var/www/html/wowflux/public/test.jpg")
e1 = cv2.getTickCount()
height, width, channels = test_image.shape

h = int(height*0.8)
w = int(width*0.8)
x = int((width-w)/2)
y = int((height-h)/2)
mask = np.zeros((height,width),dtype='uint8')
rect = (x,y,w,h)
bgdModel = np.zeros((1,65),np.float64)
fgdModel = np.zeros((1,65),np.float64)
##tmp1 = np.zeros((1, 13 * 5))
##tmp2 = np.zeros((1, 13 * 5))
cv2.grabCut(test_image,mask,rect,bgdModel,fgdModel,2,mode=cv2.
GC_INIT_WITH_REC  T)\

mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
test_image = test_image*mask2[:,:,np.newaxis]

cv2.imwrite("/var/www/html/wowflux/public/test1.jpg",test_image)
e2 = cv2.getTickCount()
time = (e2 - e1)/ cv2.getTickFrequency()
print time

For testing purposes, I have already saved the file and just testing the python script. I am facing the same problem here as well.

On my local host, Program is working fine for both the images. I am facing problem on the Amazon-EC2 instance and that too for the high resolution image. For the high resolution image, if I comment out the code for Foreground subtraction, time is getting printed. So, It is safe to assume that the problem is with running the Foreground subtraction for high resolution image.

click to hide/show revision 2
retagged

updated 2016-04-07 08:10:38 -0600

berak gravatar image

Issue while running OpenCv Python script on Amazon-Ec2 Instance

I am calling a Python script using php System() function.

Python script implements the Foreground subtraction using OpenCv library. I upload the image using Post request and then pass the file to the script.

Following things are getting executed in the code

1. Uploading file through Post request.
2. Passing the file to Python Script
3. Script reads the file, implements the 
   Foreground subtraction algorithm    
   and saves this to a new file.

I am Testing this program using two images, 1500 * 701 pixels and 2368 * 4208 pixels.

Everything is working fine for the low resolution image. But for the high resolution image, Python script keeps exiting.

Php code.

system("python /var/www/html/wowflux/public/scripts/test.py",$ret_val);
var_dump($ret_val);

Python script

import numpy as np
import cv2
import math
import os 
import sys
from sys import path
from matplotlib import pyplot as plt

##test_image = cv2.imread(sys.argv[1])
test_image = cv2.imread("/var/www/html/wowflux/public/test.jpg")
e1 = cv2.getTickCount()
height, width, channels = test_image.shape

h = int(height*0.8)
w = int(width*0.8)
x = int((width-w)/2)
y = int((height-h)/2)
mask = np.zeros((height,width),dtype='uint8')
rect = (x,y,w,h)
bgdModel = np.zeros((1,65),np.float64)
fgdModel = np.zeros((1,65),np.float64)
##tmp1 = np.zeros((1, 13 * 5))
##tmp2 = np.zeros((1, 13 * 5))
cv2.grabCut(test_image,mask,rect,bgdModel,fgdModel,2,mode=cv2.
GC_INIT_WITH_REC  T)\

mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
test_image = test_image*mask2[:,:,np.newaxis]

cv2.imwrite("/var/www/html/wowflux/public/test1.jpg",test_image)
e2 = cv2.getTickCount()
time = (e2 - e1)/ cv2.getTickFrequency()
print time

For testing purposes, I have already saved the file and just testing the python script. I am facing the same problem here as well.

On my local host, Program is working fine for both the images. I am facing problem on the Amazon-EC2 instance and that too for the high resolution image. For the high resolution image, if I comment out the code for Foreground subtraction, time is getting printed. So, It is safe to assume that the problem is with running the Foreground subtraction for high resolution image.

click to hide/show revision 3
retagged

updated 2016-04-07 08:28:46 -0600

berak gravatar image

Issue while running OpenCv Python script on Amazon-Ec2 Instance

I am calling a Python script using php System() function.

Python script implements the Foreground subtraction using OpenCv library. I upload the image using Post request and then pass the file to the script.

Following things are getting executed in the code

1. Uploading file through Post request.
2. Passing the file to Python Script
3. Script reads the file, implements the 
   Foreground subtraction algorithm    
   and saves this to a new file.

I am Testing this program using two images, 1500 * 701 pixels and 2368 * 4208 pixels.

Everything is working fine for the low resolution image. But for the high resolution image, Python script keeps exiting.

Php code.

system("python /var/www/html/wowflux/public/scripts/test.py",$ret_val);
var_dump($ret_val);

Python script

import numpy as np
import cv2
import math
import os 
import sys
from sys import path
from matplotlib import pyplot as plt

##test_image = cv2.imread(sys.argv[1])
test_image = cv2.imread("/var/www/html/wowflux/public/test.jpg")
e1 = cv2.getTickCount()
height, width, channels = test_image.shape

h = int(height*0.8)
w = int(width*0.8)
x = int((width-w)/2)
y = int((height-h)/2)
mask = np.zeros((height,width),dtype='uint8')
rect = (x,y,w,h)
bgdModel = np.zeros((1,65),np.float64)
fgdModel = np.zeros((1,65),np.float64)
##tmp1 = np.zeros((1, 13 * 5))
##tmp2 = np.zeros((1, 13 * 5))
cv2.grabCut(test_image,mask,rect,bgdModel,fgdModel,2,mode=cv2.
GC_INIT_WITH_REC  T)\

mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
test_image = test_image*mask2[:,:,np.newaxis]

cv2.imwrite("/var/www/html/wowflux/public/test1.jpg",test_image)
e2 = cv2.getTickCount()
time = (e2 - e1)/ cv2.getTickFrequency()
print time

For testing purposes, I have already saved the file and just testing the python script. I am facing the same problem here as well.

On my local host, Program is working fine for both the images. I am facing problem on the Amazon-EC2 instance and that too for the high resolution image. For the high resolution image, if I comment out the code for Foreground subtraction, time is getting printed. So, It is safe to assume that the problem is with running the Foreground subtraction for high resolution image.