Posts

Showing posts with the label opencv

Assertion failed (i2 >= 0 && i2 < static_cast(keypoints2.size())) in cv::drawMatches,

Assertion failed (i2 >= 0 && i2 < static_cast<int>(keypoints2.size())) in cv::drawMatches, Help me if anyone know about this error? Please. I had searched it many times on google but there is no proper answer, if anyone know or face it then tell me. **#read Keypoints index = [line.strip() for line in open('/Users/alisa/Desktop/ali.csv')] k = for line in index: list = line.split(',') temp = cv2.KeyPoint(x=float(list[0]), y=float(list[1]), _size=float(list[2]), _angle=float(list[3]), _response=float(list[4]), _octave=int(list[5]), _class_id=int(list[6])) print(temp) k.append(temp) # create BFMatcher object bf = cv2.BFMatcher(cv2.NORM_L2, crossCheck=True) # Match descriptors. matches = bf.match(des1,des2) print(matches) # Sort them in the order of their distance. matches = sorted(matches, key = lambda x:x.distance) # Draw first 10 matches. img3 = cv...

How do I pass OpenCV images from Python to C++?

How do I pass OpenCV images from Python to C++? How can I pass an OpenCV 3 image from Python 3 to C++? In technical terms, how do I convert a NumPy array to a cv::Mat object and back? cv::Mat To make my question more specific, let's assume: I have a Python program that uses OpenCV to capture images from the webcam and display them. (In real life, I'm prototyping further functions there, such as some web server features.) cam.py : import cv2 def main(): cam = cv2.VideoCapture(0) while True: _, img = cam.read() cv2.imshow('cam', img) # TODO: Call the C++ function from the sample below # img = helloWorld(img) cv2.waitKey(16) # let imshow do its work (16 ms -> 60 FPS) cv2.destroyAllWindows() if __name__ == '__main__': main() Run python3 cam.py to try it out. python3 cam.py I would like to use an existing helloWorld function from some C++ library that processes the OpenCV images. (In real life, it does som...

cv2.VideoWriter in RPi3 is faster than actual

cv2.VideoWriter in RPi3 is faster than actual I am trying to record the Logitech Webcam video. The cam is able to record it but 40 sec video is recorded for only 6 seconds with some nX speed. I referred the following link for the solution but it couldn't solves the problem in RPi. The important thing is the code works find in Ubuntu desktop but may be RPi is slower to process. Here is my code snippet: fourcc = cv2.cv.CV_FOURCC(*'XVID') videoOut = cv2.VideoWriter("video_clip.avi", fourcc, 20.0, (640, 480)) start_time = time.time() frame_count = 0 while True: ret, frame = cap.read() videoOut.write(frame) # write each frame to make video clip frame_count += 1 print int(time.time()-start_time) # print the seconds if int(time.time()-start_time) == 10: videoOut.release() break # get out of loop after 10 sec video print 'frame count =', frame_count # gives me 84 but expected is 20.0 * 10 = 200 ...