Showing green lines at right and bottom of recorded video using GPUImage2 - swift3

I am using example from path: GPUImage2-master/examples/iOS/SimpleVideoRecorder GPUImage2
It records proper video and saving the file in camera roll without green lines using provided code in sample.
Issue 1:
Now, I have changed some properties in ViewController.swift like
AVCaptureSessionPreset640x480 to AVCaptureSessionPresetHigh
Size(width:480, height:640) to Size(width:Float(UIScreen.main.bounds.size.width), height:Float(UIScreen.main.bounds.size.height))
and saved the video to camera roll. It saved properly. But the issue is, showing green lines at right and bottom of the recorded video and start playing with black shadow over video (in the first frame).
Why video is showing green lines.
Issue 2:
Now changed
camera = try Camera(sessionPreset:AVCaptureSessionPreset640x480)
to
camera = try Camera(sessionPreset:AVCaptureSessionPresetHigh, cameraDevice: nil, location: .frontFacing, captureAsYUV: true)
It inverts video camera to 180 degrees and also records video inverted.
Please help, I want to record video of device size.
Updated ViewController file: https://www.dropbox.com/s/ysadca77wxvw6wx/ViewController.swift?dl=0
Recorded video green lines URL: https://www.dropbox.com/s/g43ic3cxyl3h62f/test.mp4?dl=0
Inverted Recorded video URL: https://www.dropbox.com/s/2cu4me3zlqpj4ix/test%202.mp4?dl=0

Related

How to use Camera Calibration parameters on OpenCV for Augmented Reality?

So far Ive succesfully calibrated a camera with Opencv by using the chessboard pattern in the tutorials, so I got the cameraMatrix, distCoefs, Rotation and Translation vectors.
Now Id like to display an image on top of my chessboard using the calibration parameters. How can I do that?
These are the steps Ive done so far:
1 - Get the chessboard corners
2 - projectPoints to get from world (640x480) to the warped frame seen during the calibration
3 - getPerspectiveTransform to get the transformation from world to warped image
4 - warpPerspective to get the image coordinates (the image Id like to display on top of the chessboard) to warp
5 - Create a mask on top of the chessboard
6 - flip the image Id like to display
7 - And finally copy the warped image to video frame on top of the area delimited by the mask.
Corners and mask are working fine. But Im not quite sure about the rest of the process.
Can anyone help me?
see this post i think my code will help you, i have an error but to understand how to make it i think the code will be good:
https://stackoverflow.com/questions/34785237/augmented-reality-projection-cube-error
good luck
PD : The code is in python !

OpenCV/C++ - Convert a gray picture to BGR picture after some images process

I'm working on a project which consist to stabilize a video.
Therefore, during the process of stabilization, i had to convert my frames to gray in order to use some methods like goodFeaturesToTrack() or opticalFlow().
But at the end of my process, after applying my last transformation using warpAffine(), i would like to recover the colour information of the frame but i'm not able to do this. I tried some things.
I try cvtColor(outFrame,outFrame,CV_GRAY2BGR) but not working (obviously). Still back and white
At the beginning of the loop, i picked up the three colour channels B G R of my original picture like that:
Mat channel[3];
split(frameColor, channel);
And then at the end of the process, i'm doing that:
merge(channel,3,outFrame);
So i have the colour of my frame but not stabilized , that is to say it's like merging channels has removed all the transformation.
I also try to use the warpAffine() function with the colour picture but i have the same result of above.
Please help me.
Thank.
I solved my problem.
Actually when you apply a transformation like warpAffine(), you have to apply it on the previous frame and not the current. I didn't notice that i applied it to my current color frame and not the previous colour frame. And therefore, there was no changement.
By applying it on my previous colour frame, the image is in colour and stabilized.

Rotating image around a point

I'm trying to solve this one for hours and I can't figure out where I am going wrong..
On my page there is an image and a "selection frame". This frame can be moved and resized.
I am trying to make the image turn with the center point of the turn being the center of the frame.
I created a small handle at the top for rotation.
Here's the fiddle: http://jsfiddle.net/8PhqX/7/ (give it a minute to load)
The code in the fiddle is very long because I couldn't isolate the specific area relevant to my question. As you play around with it you'll see that the first rotation usually works fine, but then, things go crazy.
Here's the codeline for the rotation:
//selfRotator.handle.angle is the angle(clockwise) at which the rotation handle was rotated
//selfSelector.rotator.ox/oy is the position of the middle of the selection frame
//selfDefaults.imageArea.y is the y position of the section with the image (because of the red stripe in the top)
//selfImageArea.page.startX/Y is starting position of the image storing its position when the drag begins
//rotating by angle, at center point of selection
selfImageArea.page.transform(
['r', -selfRotator.handle.angle, selfSelector.rotator.ox - selfImageArea.page.startX, selfSelector.rotator.oy - (selfImageArea.page.startY - selfDefaults.imageArea.y)]
)
//tracking the image's start position and compensating
selfImageArea.page.attr({
transform: "...T" + (selfImageArea.page.startX) + "," + (selfImageArea.page.startY - selfDefaults.imageArea.y)
});
It looks like it gets messed up because of the getBBox values that don't follow the picture outlines.
I've added gridlines to illustrate the problem
also, iv'e came across this code(https://groups.google.com/forum/#!topic/raphaeljs/b8YG8DfI__g) for "getBBoxRotated()" function that should solve my issue but I can't seem to implement it.

Region of Interest in Video File

This is my first time posting here and hoping for a positive result since my research is near its conclusion.
I want to add in my code a function that will process only the defined region of interest of a video file.
(I can't post image since I don't have yet a reputation but same question is posted here --->
http://answers.opencv.org/question/18619/region-of-interest-in-video-file/)
Storyboard:
I'm making a program in C++/OpenCV that will make the pedestrians and vehicles look that they are not in the scene/disappear by getting the running average of the videos frame. I already made that. Now my problem is I do want only the portion of the video that is under the region of interest to be processed because I want to preserve the Lighting/Illumination of the Christmas lights while they are blinking.
Why? I want to use this method to capture only the blinking lights this coming yuletide season without the disturbance of vehicle and people in the scene.
How can I do that? I mean getting a region of interest in a video file.
Thanks in advance.
Fix your ROI Position.
Take the region from each frame of the video.
Then process it.
Apply for all frames.
Like this:
cv::Rect ROI(startX,startY,width,height);
while(1)
{
cap.read(frame);
temp = frame(ROI);
process(temp);
}

how to cut Faces after detection

I have been working on a college project using OpenCV. I made a simple program which detects faces, by passing frames captured by a webcam in a function which detects faces.
On detection it draws black boxes on the faces when detected. However my project does not end here, i would like to be able to clip out those faces which get detected as soon as possible and save it in an image and then apply different image processing techniques [as per my need]. If this is too problematic i could use a simple image instead of using frames captured by a webcam.
I am just clueless about how to go about clipping those faces out that get detected.
For C++ version you can check this tutorial from OpenCV documentation.
In the function detectAndDisplay you can see the line
Mat faceROI = frame_gray( faces[i] );
where faceROI is clipped face and you can save it to file with imwrite function:
imwrite("face.jpg", faceROI);
http://nashruddin.com/OpenCV_Region_of_Interest_(ROI)
Check this link, you can crop the image using the dimensions of the black box, resize it and save as a new file.
Could you grab the frame and crop the photo with the X,Y coordinates of each corner?