Hi, I'm new to JeVois. I have a coding that is using the webcam to run but now I am trying to run it on the JeVois Camera. I have no idea how to develop a software to run my coding on JeVois so I decide to use the GUVC software to run my coding. I am now trying to edit the PythonOpenCV module in JeVois and overwrite it with my code because I am gonna using its video mapping to execute my coding in the GUVC software. But the problem is I do not know how to put my coding in the correct sequence in the JeVois module. Anyone can help? Big thanks.
###PythonOpenCV module###
import libjevois as jevois
import cv2
import numpy as np
## Simple example of image processing using OpenCV in Python on JeVois
#
# This module by default simply converts the input image to a grayscale OpenCV image, and then applies the Canny
# edge detection algorithm. Try to edit it to do something else (note that the videomapping associated with this
# module has grayscale image outputs, so that is what you should output).
#
# @author Laurent Itti
#
# @displayname Python OpenCV
# @videomapping GRAY 640 480 20.0 YUYV 640 480 20.0 JeVois PythonOpenCV
# @email itti\@usc.edu
# @address University of Southern California, HNB-07A, 3641 Watt Way, Los Angeles, CA 90089-2520, USA
# @copyright Copyright (C) 2017 by Laurent Itti, iLab and the University of Southern California
# @mainurl
http://jevois.org
# @supporturl
http://jevois.org/doc
# @otherurl
http://iLab.usc.edu
# @license GPL v3
# @distribution Unrestricted
# @restrictions None
# @ingroup modules
class PythonOpenCV:
# ###################################################################################################
## Constructor
def __init__(self):
# Instantiate a JeVois Timer to measure our processing framerate:
self.timer = jevois.Timer("canny", 100, jevois.LOG_INFO)
# ###################################################################################################
## Process function with no USB output
#def process(self, inframe):
# jevois.LFATAL("process with no USB output not implemented yet in this module")
# ###################################################################################################
## Process function with USB output
def process(self, inframe, outframe):
# Get the next camera image (may block until it is captured) and convert it to OpenCV GRAY:
inimggray = inframe.getCvGRAY()
# Start measuring image processing time (NOTE: does not account for input conversion time):
self.timer.start()
# Detect edges using the Canny algorithm from OpenCV:
edges = cv2.Canny(inimggray, 100, 200, apertureSize = 3)
# Write frames/s info from our timer into the edge map (NOTE: does not account for output conversion time):
fps = self.timer.stop()
height, width = edges.shape
cv2.putText(edges, fps, (3, height - 6), cv2.FONT_HERSHEY_SIMPLEX, 0.5, 255, 1, cv2.LINE_AA)
# Convert our GRAY output image to video output format and send to host over USB:
outframe.sendCvGRAY(edges)
# ###################################################################################################
## Parse a serial command forwarded to us by the JeVois Engine, return a string
def parseSerial(self, str):
return "ERR: Unsupported command"
# ###################################################################################################
## Return a string that describes the custom commands we support, for the JeVois help message
def supportedCommands(self):
return ""
#######################################################################################
###My coding###
#This module is to detect a single line and measure its angle
import cv2
import numpy as np
import math
import time
cap = cv2.VideoCapture(0)
num = 0
#Start video cam
while(True):
ret,frame = cap.read()
cv2.imshow("camera",frame)
#Taking a picture
for num in range (1):
cv2.imwrite('pic'+str(num)+'.jpg',frame)
num +=1
#Read the picture
img = cv2.imread('pic0.jpg')
#Crop the picture and save it
imge = img[100:350,100:300].copy()
cv2.imwrite('Resize.jpg',imge)
cv2.waitKey(1)
#Read the cropped picture
imf = cv2.imread('Resize.jpg')
#Convert to Grayscale
gray = cv2.cvtColor(imf,cv2.COLOR_BGR2GRAY)
#Canny Edge Detection
edges = cv2.Canny(gray,50,150,apertureSize = 3)
#Hough Line Transform
lines = cv2.HoughLines(edges,1,np.pi/180,100)
if lines is None:
continue
for rho,theta in lines[0]:
a = np.cos(theta)
b = np.sin(theta)
x0 = a*rho
y0 = b*rho
x1 = int(x0 + 1000*(-b))
y1 = int(y0 + 1000*(a))
x2 = int(x0 - 1000*(-b))
y2 = int(y0 - 1000*(a))
#Draw line on the cropped picture
cv2.line(imf,(x1,y1),(x2,y2),(0,255,0),1)
#Save the cropped picture with line
cv2.imwrite('houghlines3.jpg',imf)
#Angle measurement formula
cx = float(x1)
cy = float(y1)
cx2 = float(x2)
cy2 = float(y2)
angle = int(math.atan2((cy - cy2), (cx2 - cx))* 180 // math.pi)
#Display the angle
print angle