"Turn" finally did a bit of work. Three days with three libraries OpenCV, EMGU, aforge.net[2011.7.30]

Source: Internet
Author: User

The original text turns from:

http://blog.csdn.net/tutuguaiguai0427/article/details/6646051

These days, I have seen a lot of things. Although not diligent mostly.

The last log said something finished after the temporary will be OK, and then nest laboratory blowing air conditioning to do my hut.

Later I really feel bored to find something to do.

The first day is intended to eliminate the video watermark. In fact, the most effective method is single frame PS, but, obviously I am not so diligent person. I am not learning PS, I always think this is a design and other people use.

Then remember the last time in the Xiaotie blog read the program in addition to watermark, and turned out the article, the specific code is not, only ideas.

Although he said the translucent watermark can go, or not repair.

However, in order to eliminate the completely opaque watermark, I still tried his method.

1. Make a mask image manually. Think of a video also on p a figure can withstand, if not manually, this program can be trouble, not to mention the effect is not necessarily good. I first put the video to play with OpenCV, put a frame to write a picture, so you can pick a pure little picture easy to key watermark.

2. Test the effect of a single picture. Randomly load a picture with that watermark, and then use the watermark image of PS to make mask, with inpaint function. Adjust a few radius, the effect is general, you can remove the watermark but there is always noise in that piece of land. If the video is not clear, the noise is more, or you need to re-hit your own watermark (this is more evil) that is OK. Mask different out of the effect is also different, I tried to precisely by the text shape and directly into a variety of mask. Some come out is a lump of noise, some is a small piece of a small piece of.

3. Actually I did not do 3, the second step effect good words in fact, the third step is similar to batch processing, that is, playing video, reading frames, processing, writing frames. And then there's the wood.

Note that when using the Inpaint function, it should be said that when using mask, the mask is not directly with PS painted black and white can be. Mask requires a single-channel 8-bit picture, after several unsuccessful tries I loaded the picture, and then the program processed into 8-bit single channel. After processing can also save, and then directly read the image as mask on it. Processing with the threshold () function, each pixel is not 0 is 1. When you use mask, you don't deal with the 0 point.

Then that will be over, then do a video capture, playback, recording function of the software, the picture also to increase the text and the current system time, interface with C #.

Just open the OpenCV for inertial thinking and you'll get it done within an hour. Then C # write interface, C + + managed, done. Then the root of the tragedy is to try to OpenCV jump out of the box into C #, anyway, that effect, understand.

In fact, there is this problem, C#+OPENGCV that the video playback window can not be fixed, only from the interface pop out. But then escaped, and then switched to the WMP control, because that was only playing local video, WMP also directly support the scroll bar forward and backward, really cool. But this time, I can't escape. After a variety of problems such as bitmap, handles, and so on, it is possible to find a way to set the parent window.

[CPP]View Plaincopy
  1. Cvnamedwindow ("Capture");
  2. To minimize this window
  3. Cvresizewindow ("Capture", 1, 1);
  4. Get Window Handle
  5. HWND hwnd = (hwnd) Cvgetwindowhandle ("Capture");
  6. Gets the parent window handle of the window
  7. hwnd Hparent =:: GetParent (HWND);
  8. Get C#form1 Window Handle
  9. HWND Hwnd1=::findwindoww (null,l"Form1");
  10. HWND Hwnd2=::findwindowex (hwnd1,null,null,l "PictureBox1");//This incredibly failed, will be positioned to the upper left corner of the desktop HWND Hwnd3=::findwindowex (HWND1, Null,null,null);
  11. if (!hwnd3) Cvnamedwindow ("C"); In fact, this function is similar to the message, I write, the magic is, do not add this sentence when how can not, a plus incredibly good, and then I did not change
  12. Sets the GUI window as the parent window of the video playback window so that the video plays in the specified area of the GUI
  13. :: SetParent (HWnd, Hwnd3);
  14. //Hide the Created video playback window:: ShowWindow (Hparent, sw_hide);

But this will still jump out of a box, and then it will go into the C # interface, it is estimated that the computer card will be obvious. Whining.

Before using OPENCV with the Waitkey method with the keyboard to control the recording, and other functions.

But when the key point must be in the OpenCV window, so it is tragic.

It took a long time not to fix, do not know how to let the focus on the jumping out of the window, this time is hidden.

I don't know how to do it anyway. In this desolate to long grass blog, I think there should not be a few people to read my diary, and then no one will answer this question.

Think for a long time, think in fact, such a few ideas, one is to find a way to put that hidden focus, the second is to pass events, from C # to DLL C + +, three is OpenCV write that part only return pictures, or to bitmap.

The first two I have failed, the third of various entanglements later found that if not OPENCV conversion, C # and C + + are only aware of their own type of picture, it is said that the CLR can also support the C # that, but I do not.

OPENCV conversion has a function, 2.2 version just cancel, someone put it out, I added the hint after the missing a header file, added after the discovery is MFC, and then the configuration to change, not to support the original. In short, also failed.

When he asked for help, he said that the control of those keys could not be written in OpenCV, must return the picture from OpenCV, as for conversion he is memory RGB stream written bitmap. So, I know, my road is not going to go on. After the conversion of this efficiency is not know what kind of.

Most of those searched on the Internet are EMGU, and in C # It seems that OpenCV is not much. I also found this debugging inconvenient.

continued to struggle for a long time, attempted, decided to use MFC, but, again gave up, back to C #.

This time chose the EMGU. Really convenient, no hosting, functions are readily available.

Full of hope to run, found that the camera display is always black, the text you added can be seen.

It is also the case to go to Emgu's own example to run.

Then I collapsed, the last time with EMGU is a variety of configuration problems, then OpenCV and EMGU are replaced by 64 bit on it, this time even 64 can not ah. Program in others 32 of the machine run, Emgu replaced 32, engineering also choose 32, even a frame did not take. ORZ.

Struggled for a long time I decided to continue to abandon EMGU, then, the target turned to aforge.net. I heard it was strong but there was very little information. At the time of the pipe it has no information, anyway the camera capture this to the visual library originally felt a little overkill meaning. Never touched this, download, install. found that the latest version was released after the 27th, which just added a new class to write video files. Nice.

As with EMGU, the development efficiency is also very high. This lesson will first try the system comes with an example of whether it can run. The facts proved to be very successful.

Be assured of bold writing. It wasn't long before it was OK. Run. Collapsed again. The newly added library failed to load. "Could not load file or assembly ' AForge.Video.FFMPEG.dll ' or one of its dependencies. The specified module could not being found. " The heart that wants to die has all.

This library is very informative. Find the Forum on the official website, found that the whole forum Afoge.net framework part only a few people sent a post to ask questions, and then basically only the administrator in the answer.

The location of the administrator is also the United Kingdom. I do not know which nationality, anyway, are English post.

Sent a post to ask after the last day because the bedroom was too hot a whole night did not fall asleep so lying on the bed. Woke up to find the administrator replied. Let me copy the DLL under Externals\ffmpeg\bin to the output folder of the project. After that.

"Mixed mode assembly is built against version ' v2.0.50727 ' of the runtime and cannot being loaded in the 4.0 runtime without Additional configuration information. ", continue to send the error message to the post. Soon the administrator replied. That's a nice guy. Gave me a post link, is Google out of the results, but also very implicitly told me to diligent Google. Sweat.

The first method is to modify the App.exe.config

[HTML]View Plaincopy
  1. <? XML version="1.0"?>
  2. <configuration>
  3. <startup><supportedruntime version="v4.0" sku= ". Netframework,version=v4.0,profile=client "/></startup></Configuration >


The second is to drop the 4.0 down.

I don't have the config file because I didn't compile it successfully. (It's silly to think about that library, then.) )

So we can only fall into. NET3.5. Also compiled 2.0 of the DLL itself. Compile my project again. As a result, the DLL that preceded the problem was actually dependent. The NET4.0 file. ORZ.

So I can only change back to 4.0. At this time actually found can run to say. But for the sake of insurance, I still changed the CONFIG.

When I run, I can use the USB camera when I am recording and I can't use my laptop. A preview is all you can.

Again asked the administrator GG, others quickly reply, said this library does not recognize you use is what equipment, should be other problems.

And then when I put the FPS settings removed, the band can be used, the USB strike.

After that, try a variety of FPS, and found that the setting 8 can be used.

Using the system's own example, the fps,usb of the camera is measured in 8-9, which is 9-10, since that is the dynamic measurement.

Then you can only set FPS, try will not hang.

And the time added to the text. Time is well implemented, C # has corresponding functions. But OPENCV is not supported by adding Chinese strings, emgu so is not supported. With Aforge. NET is a time to go. OpenCV someone is installed font to achieve, look good complex.

As for many people also have a problem, is recorded in the video particularly fast. Especially since I've added time, it's clear that it's fast.

I finally figured it out today. I overestimate my camera. Avi Frame rate Set 25, previously did not find the camera even half of its frame rate is not to, that is, a second to catch 10 frames, I stare at 25 frames to AVI, of course, go fast, and then add compression should also have lost. But when I set the file to a very low time, sometimes there will be errors, the same as the previous set FPS error, said the video file can not be opened (in fact, is created).

When I write here, I suddenly think, if it is still fps25, ignoring the problem of coherence, only to consider the accurate time, maybe set a timer, a fixed period of writing, regardless of whether there is a new frame, anyway, a variable inside a new frame is replaced, did not continue to write the original. A try, this estimate doesn't take much time. If you still can't do it first.

Because there are new tasks now, do a video summary.

Babe, come on, oh yes.

"Turn" finally did a bit of work. Three days with three libraries OpenCV, EMGU, aforge.net[2011.7.30]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.