Hello guys,
As suggested in this [post](http://answers.opencv.org/question/200193/svm-predict-error-on-opencv4android/), I implemented in C++, the same method I used to train my SVM in C #. Initially, I load the vocabulary generated by the program in C# through a JNI call in C++, because the FileStorage class is not available in OpenCV4Android:
JNIEXPORT
void JNICALL Java_test_vision_MainActivity_loadVocabulary(
JNIEnv* env,
jobject,
jstring vocabularyPath,
jlong addrVocabulary)
{
const char *str = env->GetStringUTFChars(vocabularyPath, 0);
Mat& vocabulary = *(Mat*)addrVocabulary;
cv::FileStorage opencv_file(str, cv::FileStorage::READ);
opencv_file["vocabulary"] >> vocabulary;
opencv_file.release();
}
After that, I load an image through Java, and pass the Mat object to a second C++ method, which has all the implementation of BagOfWords and SVM Predict.
Java:
Mat image = Utils.loadResource(MainActivity.this, R.raw.image, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
predict(trainedData,
vocabularyMat.getNativeObjAddr(),
image.getNativeObjAddr(),
bowDescriptor.getNativeObjAddr());
C++
JNIEXPORT
void JNICALL Java_test_vision_MainActivity_predict(
JNIEnv* env,
jobject,
jstring trainedData,
jlong addrVocabulary,
jlong addrRgba,
jlong addrBowDescriptor) {
const char *str = env->GetStringUTFChars(trainedData, 0);
Mat& vocabulary = *(Mat*)addrVocabulary;
Mat& bowDescriptor = *(Mat*)addrBowDescriptor;
int dictionarySize = 32;
Ptr extractor = KAZE::create();
Ptr bFMatcher = new BFMatcher(cv::NORM_L2);
Ptr bOWKMeansTrainer
= new BOWKMeansTrainer(
dictionarySize,
TermCriteria(
TermCriteria::MAX_ITER +
TermCriteria::EPS,
10,
0.0001),
1, KMEANS_PP_CENTERS);
Ptr bOWImgDescriptorExtractor =
new BOWImgDescriptorExtractor(extractor, bFMatcher);
Ptr svm = ml::SVM::create();
svm->setType(ml::SVM::C_SVC);
svm->load(str);
bOWImgDescriptorExtractor->setVocabulary(vocabulary);
std::vector keyPoints;
Mat& src = *(Mat*)addrRgba;
try {
extractor->detect(src, keyPoints);
bOWImgDescriptorExtractor->compute(src, keyPoints, bowDescriptor);
} catch(exception& e) {
const char *teste = e.what();
cout << teste;
}
float response = svm->predict(bowDescriptor);
cout << response;
}
However, I have received this error when calling bOWImgDescriptorExtractor.compute:
**"OpenCV(3.4.3) /build/3_4_pack-android/opencv/modules/core/src/batch_distance.cpp:238: error: (-215:Assertion failed) type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U) in function 'void cv::batchDistance(cv::InputArray, cv::InputArray, cv::OutputArray, int, cv::OutputArray, int, int, cv::InputArray, int, bool)'\n"**
Sorry for the size of the question, but I tried to put as much information as possible.
Thank you.
↧
BagOfWords works in C#, but not in C++
↧
Concerning SimpleBlobDetect what max params should I try?
So far most of the tutorials that cover SimpleBlobDetect cover min values for, e.g.,
// Filter by Circularity
params.filterByCircularity = true;
params.minCircularity = 0.1;
// Filter by Convexity
params.filterByConvexity = true;
params.minConvexity = 0.87;
// Filter by Inertia
params.filterByInertia = true;
params.minInertiaRatio = 0.01;
Thx in advance & sorry I can't get the code tag to work correctly.
↧
↧
distanceTransform not working in Xcode
From my understanding if I have an image like this [original image](https://i.stack.imgur.com/pYe0w.png) and it uses OpenCV distanceTransform to process the image, it should look like [distanceTransform image](https://i.stack.imgur.com/0bb9e.png)
But when I tried to use distanceTransform in Xcode it will never return an image to my imageview.
I have tried to change `distanceTransformMat` in `UIImage *outputImg = MatToUIImage(distanceTransformMat);` to `thresholdMat`.
To check for which line of code is wrong, I have changed `UIImage *outputImg = MatToUIImage(thresholdMat);` instead of `distanceTransformMat` and `threshholdMat` is able to get a return
Does anyone know why is this happening?
↧
Absolute phase unwrapping of a fringe pattern
Hi all,
I am looking for advice on what is the best technique for absolute phase unwrapping of a fringe pattern. As best I can tell the following tutorial only phase unwraps relatively meaning it doesn't take into account the 2 * pi jumps in the fringe pattern.
https://docs.opencv.org/3.4/d9/dfb/tutorial_unwrap.html
Working code / example link on how to accomplish the absolute phase unwrapping would be really appreciated
Thanks in advance
↧
OpenCV / C++ - Filling holes
Hello there,
For a personnel projet, I'm trying to detect object and there shadow. These are the result I have for now:
Original:

Object:

Shadow:

The external contours of the object are quite good, but as you can see, my object is not full.
Same for the shadow.
I would like to get full contours, filled, for the object and its shadow, and I don't know how to get better than this (I juste use "dilate" for the moment).
Does someone knows a way to obtain a better result please?
Regards.
↧
↧
What's the future of cuda modules after Opencv 4
All cuda modules have been moved to opencv_contrib, what is the plans? will openGL replace these modules?
↧
How to find position and orientation from an image?
Since i'm new to image and computer vision technique, i have red ball placed on a black colored automated guided vehicle. I'm using 2 depth camera from Intel to localize the vehicle. So by tracking the ball as a point, is it possible to get exact position and orientation from the images?
↧
FacemarkLBF Params model_filename error
Hi there OpenCv community!
I'm brand new to OpenCV and I've been trying to build a real time face tracking app using Landmark (from the OpenCV contrib)
And when I try to create my facemark ptr, I give it a FacemarkLBF::Params variable. The issue is that the model_filename variable in the Params struct has an error of "Error reading characters of string" when I create the params. Therefore if I try to access the model_filename the program crashes with a read access violation error.
Is this a known issue? I am using OpenCV 3.4.3 and the latest version of the OpenCV contrib from Github.
Here is the code:

↧
How do I correct grammatical mistakes on opencv.wiki?
In the Coding_Style_Guide wiki there is a grammatical error, and I would like to correct it.
It currently says: "The function should be ***easy*** embedded into different processing pipelines that use other OpenCV functions."
when it should say: "The function should be ***easily*** embedded into different processing pipelines that use other OpenCV functions."
I cloned the wiki - but could not see how to do a PR or anything for wiki.
↧
↧
Errors occuring for unchanged code that previously functioned fine
I have previously (a few months ago) managed to build my program with no problems, however I tried doing so today, with all code unchanged, and I presented with these errors. Is anyone able to tell me what I would need to do to fix this?
10:25:05: Starting: "/usr/bin/make"
g++ -o OMR main.o OMR.o svm.o score.o moc_OMR.o -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
/usr/bin/ld: warning: libImath-2_2.so.12, needed by /usr/local/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libIlmImf-2_2.so.22, needed by /usr/local/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libIex-2_2.so.12, needed by /usr/local/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libHalf.so.12, needed by /usr/local/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libIlmThread-2_2.so.12, needed by /usr/local/lib/libopencv_imgcodecs.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libavcodec.so.57, needed by /usr/local/lib/libopencv_videoio.so.3.3, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libavformat.so.57, needed by /usr/local/lib/libopencv_videoio.so.3.3, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libavutil.so.55, needed by /usr/local/lib/libopencv_videoio.so.3.3, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libswscale.so.4, needed by /usr/local/lib/libopencv_videoio.so.3.3, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libavresample.so.3, needed by /usr/local/lib/libopencv_videoio.so.3.3, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_write_frame@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avcodec_flush_buffers@LIBAVCODEC_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avformat_free_context@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_reduce@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_rescale_q@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_write_trailer@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::ChannelList::insert(char const*, Imf_2_2::Channel const&)'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_free@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avcodec_encode_video2@LIBAVCODEC_57'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::hasChromaticities(Imf_2_2::Header const&)'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avcodec_decode_video2@LIBAVCODEC_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avcodec_get_context_defaults3@LIBAVCODEC_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_log_set_level@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::InputFile::readPixels(int, int)'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::InputFile::setFrameBuffer(Imf_2_2::FrameBuffer const&)'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avformat_get_riff_video_tags@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avformat_network_init@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avcodec_close@LIBAVCODEC_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avformat_find_stream_info@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avformat_open_input@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_register_all@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_packet_unref@LIBAVCODEC_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_frame_free@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::Header::channels() const'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_frame_unref@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avformat_get_mov_video_tags@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::InputFile::InputFile(char const*, int)'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_opt_set@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::FrameBuffer::insert(char const*, Imf_2_2::Slice const&)'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_image_get_buffer_size@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::chromaticities(Imf_2_2::Header const&)'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_frame_get_buffer@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avformat_alloc_context@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_read_frame@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_dict_parse_string@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_frame_alloc@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avformat_write_header@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_dict_set@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::globalThreadCount()'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_image_fill_arrays@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avcodec_find_encoder@LIBAVCODEC_57'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::InputFile::header() const'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `sws_getCachedContext@LIBSWSCALE_4'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_seek_frame@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::OutputFile::writePixels(int)'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_lockmgr_register@LIBAVCODEC_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avcodec_open2@LIBAVCODEC_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_malloc@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avio_close@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_init_packet@LIBAVCODEC_57'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::Channel::Channel(Imf_2_2::PixelType, int, int, bool)'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_mallocz@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avformat_close_input@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_guess_codec@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::Slice::Slice(Imf_2_2::PixelType, char*, unsigned long, unsigned long, int, int, double, bool, bool)'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avio_open@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::OutputFile::setFrameBuffer(Imf_2_2::FrameBuffer const&)'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_guess_format@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::Header::dataWindow() const'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `sws_getContext@LIBSWSCALE_4'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avformat_new_stream@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `half::_eLut'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::Header::channels()'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_sub_q@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::Header::~Header()'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::OutputFile::OutputFile(char const*, Imf_2_2::Header const&, int)'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::ChannelList::findChannel(char const*) const'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_freep@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `avcodec_find_decoder@LIBAVCODEC_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_codec_get_tag@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `sws_scale@LIBSWSCALE_4'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `sws_freeContext@LIBSWSCALE_4'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::Header::Header(int, int, float, Imath_2_2::Vec2 const&, float, Imf_2_2::LineOrder, Imf_2_2::Compression)'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_dict_free@LIBAVUTIL_55'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `half::convert(int)'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::Chromaticities::Chromaticities(Imath_2_2::Vec2 const&, Imath_2_2::Vec2 const&, Imath_2_2::Vec2 const&, Imath_2_2::Vec2 const&)'
/usr/bin/ld: /usr/local/lib/libopencv_videoio.so.3.3: undefined reference to `av_codec_get_id@LIBAVFORMAT_57'
/usr/bin/ld: /usr/local/lib/libopencv_imgcodecs.so: undefined reference to `Imf_2_2::OutputFile::~OutputFile()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:288: OMR] Error 1
10:25:06: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project OMR (kit: Desktop)
When executing step "Make"
↧
GStreamer unable to query pipeline state on Ubuntu18.04 with Opencv4
I have the same problem described [here]( http://answers.opencv.org/question/195351/342-cannot-open-and-create-videos-but-with-341-i-can/) but with Ubuntu 18.04.
The program runs and does not stop but it does not catch the keyboard input and as soon as it starts I get the error
(process:11477): GStreamer-CRITICAL **: 18:44:25.567: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed
OpenCV | GStreamer warning: GStreamer: unable to query pipeline state (/home/fra/Documents/openCV/openCV/modules/videoio/src/cap_gstreamer.cpp:420)
I have installed the gstreamer libraries because they were required by opencv and I am including and linking them in the Makefile like this (see the complete Makefile later):
Have anyone had the same problem? What is generating the exception?
I am thinking the error is related to Opencv deendencies but I am not sure is not a problem related to SDL2.0.
SOURCE CODE OF THE C++ PROGRAM
Here is a minimal working example: clicking the left and right buttons of the mouse works (catched directly with Opencv callbacks) while pressing and releasing the keyboard buttons does not call the proper SDL callback. The script can be launched with ./executable camID anyNameYouWant where camID is an integer (typically 0 or 1) that identifies the cam you want to use.
#ifndef __OPENCV__
#define __OPENCV__
#include "opencv2/opencv.hpp"
#endif
#include
//#include "utils.hpp"
//#include "constants.hpp"
#include
#include
#include
#include
using namespace cv;
using namespace std;
static const int delay = 2;
#define WINDOW_SCALE 1.7
void onTrackbar_changed(int, void* data);
void onMouse(int evt, int x, int y, int flags, void* param);
void PrintKeyInfo( SDL_KeyboardEvent *key );
int keyboardCallback(SDL_KeyboardEvent ev);
//InputStateContext context;
int main(int argc, char* argv[])
{
/* Initialise SDL */
if( SDL_Init( SDL_INIT_VIDEO ) < 0)
{
fprintf( stderr, "Could not initialise SDL: %s\n", SDL_GetError() );
exit( -1 );
}
string host;
unsigned int port;
const String sourceReference = argv[1];
int camNum;
string sensorName;
try
{
camNum = stoi(sourceReference); // throws std::length_error
}
catch (const std::exception& e)// reference to the base of a polymorphic object
{
std::cout<<"Exception: " << e.what()<4)
{
try
{
host = argv[2];
port = atoi(argv[3]);
sensorName = argv[4];
}
catch (const std::exception& e)
{
cout<<"impossible to convert host or port"<2)
{
cout<<"argumetns less than 4"<>frame;
resize(frame, frame, cv::Size(frame.cols/WINDOW_SCALE, frame.rows/WINDOW_SCALE));
resizeWindow("Camera", cv::Size(frame.cols/WINDOW_SCALE, frame.rows/WINDOW_SCALE));
setMouseCallback("Camera", onMouse, &frame);
while(1)
{
while( SDL_PollEvent( &keyboardEvent) )
{
switch( keyboardEvent.type )
{
/* Keyboard event */
/* Pass the event data onto PrintKeyInfo() */
case SDL_KEYDOWN:
break;
case SDL_KEYUP:
keyboardCallback(keyboardEvent.key);
break;
/* SDL_QUIT event (window close) */
case SDL_QUIT:
return 0;
break;
default:
break;
}
}
Mat frame_out;
frame_out = frame.clone();
cam>>frame;
resize(frame_out, frame_out, cv::Size(frame.cols/WINDOW_SCALE, frame.rows/WINDOW_SCALE));
imshow("Camera", frame_out);
/* A delay is needed to show (it actually wait for an input)*/
if(waitKey(delay)>delay){;}
}
return 0;
}
void onMouse(int evt, int x, int y, int flags, void* param)
{
if(evt == EVENT_LBUTTONDOWN)
{
cout<<"Left button pressed"<
↧
Static video
Hi,
I want to check if recieved image is freezed, eg. ip camera is sending the same frame all the time. I decided to simulate freeze with test avi video like this:
https://www.youtube.com/watch?v=woXNRYAlbNg
, theoretically difference between two cv::mat frames (with 4 sec. interval) should be zero. But it isn't. Does anybody can help me?
Here is code:
cv::Mat frame1, frame2;
cv::VideoCapture cap;
cap.open("myTestVid.avi");
cap.read(frame1);
sleep(3);
cap.read(frame2);
compareFrames(frame1, frame2);
And here is compareFrames method:
void CompareWorker::compareFrames(Mat frame1, Mat frame2)
{
// std::cout << "compare frames";
QImage firstImage((const unsigned char *)(frame1.data), frame1.cols, frame1.rows, QImage::Format_RGB888);
QImage secondImage((const unsigned char*)(frame2.data), frame2.cols, frame2.rows, QImage::Format_RGB888);
double totaldiff = 0.0;
double diffLevelVal = 0.0 ;
if((frame1.rows == frame2.rows) && (frame1.cols == frame2.cols)){
for ( int y = 0 ; y < firstImage.height() ; y++ ) {
//odczytywanie linii obrazków
uint *firstLine = ( uint* )firstImage.scanLine( y ) ;
uint *secondLine = ( uint* )secondImage.scanLine( y ) ;
for ( int x = 0 ; x < firstImage.width() ; x++ ) {
uint pixelFirst = firstLine[ x ] ;
int rFirst = qRed( pixelFir ) ;
int gFirst = qGreen( pixelFir ) ;
int bFirst = qBlue( pixelFir ) ;
uint pixelSecond = secondLine[ x ] ;
int rSecond = qRed( pixelSec ) ;
int gSecond = qGreen( pixelSec ) ;
int bSecond = qBlue( pixelSec ) ;
double rDiff = std::abs(rFirst - rSec)/255.0;
totaldiff+=rDiff;
double gDiff = std::abs(gFirst - gSec)/255.0;
totaldiff+=gDiff;
double bDiff = std::abs(bFirst - bSec)/255.0;
totaldiff+=bDiff;
}
}
}
diffLevelVal = ((totaldiff * 100) / (firstImage.width() * firstImage.height() * 3));
emit returnDiffVal(diffLevelVal);
}
↧
Error while running the program : "program has stopped working"
I built `OpenCV 4.0.0-pre` from source using `MinGW (tdm-1) 5.1.0` which was shipped along with codeblocks.
My build and install were successful on windows 10.
[image](https://imgur.com/a/IWFrXc7)
Now, to check my built library I ran a sample program,
#include
#include
#include
#include
using namespace cv;
using namespace std;
int main( )
{
// Create black empty images
Mat image = Mat::zeros( 400, 400, CV_8UC3 );
// Draw a line
line( image, Point( 15, 20 ), Point( 70, 50), Scalar( 110, 220, 0 ), 2, 8 );
imshow("Image",image);
cout<<"******************";
waitKey( 0 );
return(0);
}
Using below command I can compile my program and get the executable
g++ -std=c++11 OpenCVTest.cpp -llibopencv_core400 -llibopencv_highgui400 -llibopencv_imgproc400
But on running the program, I am getting **program has stopped working** pop up. [image](https://imgur.com/a/fXihGc8)
Had raised this issue on OpenCV Github repo but didn't got any answer. [github issue](https://github.com/opencv/opencv/issues/12720)
Any help would be appreciated. Thanks..
↧
↧
Error - ReadProtoFromBinaryFile
Hi,
Although this a basic issue. But still can anyone help me regarding this.
This is the error i am getting when i try to load model-weights & text-graph.
Opencv Version: '3.4.3'
Ubuntu : 18.04
**net = cv.dnn.readNetFromTensorflow("/home/mask_rcnn_inception_v2_coco_2018_01_28/mask_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb", "/home/mask_rcnn_inception_v2_coco_2018_01_28/mask_rcnn_inception_v2_coco_2018_01_28.pbtxt")
cv2.error: OpenCV(3.4.3) /io/opencv/modules/dnn/src/caffe/caffe_io.cpp:1132: error: (-2:Unspecified error) FAILED: fs.is_open(). Can't open "/home/mask_rcnn_inception_v2_coco_2018_01_28/mask_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb" in function 'ReadProtoFromBinaryFile**
↧
Image Subtraction using frame history
Hello Everyone,
I am trying to use image subtraction for extracting contours from the video. I just need to subtract the average of the first 20 frames for this particular problem. However, I figured out that current algos substract on a rolling image basis.
My current approach is:
1. Adding first 20 frames and then dividing by 20 to get average of the background
2. Substracting the averaged image from frames >20.
Is there any other way ?
Any help would be greatily appreciated ?
↧
installing opencv with visual studio 2017
So, I was attempting to install OpenCV using Pre-built libraries per Bernát Gábor's tutorial. The last step is to set the OpenCV environment variable and add it to the path of the system.
I had two issues at this step: *1. What would be the correct command line prompt for Visual Studio 17 (none given in tutorial)* and **2. I get this message(ERROR: Access to the registry path is denied) even when I input the command line for VS 15.**
↧
#include error with CLR compilation with opencv-4.0.0-alpha-vc14_vc15.exe
Dears all,
I just want to make a report: When developping application with opencv-4.0.0-alpha-vc14_vc15.exe there is an error of compilation with VC2017.
"E0035 directive #error : is not supported when compiling with /clr or /clr:pure. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include\mutex 8"
By investigating: only the header file "utility.hpp" use "#include < mutex >" line 61.
How could fixe this issue?
With the opencv realease 343, there is no this error. It means "utility.hpp" in this realease didn't use #include .
Thank a lot for help in the future to maintain the possibility to developp Opencv application under VC with CLR.
↧
↧
How can I adjust shutter speed of a raspberry pi camera using OpenCV?
I need to take pictures of laser light and process the pictures to crate sensing system of actuator. So I thought that I can take noiseless pictures of laser light by setting shutter speed higher.
After that, I confirm I can take noiseless pictures in high-speed shutter, but I don't know how to adjust shutter speed using OpenCV.
Can any one tell me the solution strategy?
↧
After calibration, my disparity map is paint
I use two MS lifecam HD-3000(baseline = 3.4cm).
I calibrate my webcams, and calibrate together than rectify.
Also remap the image than make disparity map. However, it looks paint

I don't know where is my fault.
Personally, I think my calibration is fault... if anyone knows that situation plz advise.
↧
Floodfill not working also Mat.get(col,row) is returning wrong color
the floodfill is not effecting the bitmap also the Mat.get(col,row) is returning wrong color.
Things I have done:
1) checked that bitmap and matrix are of same size.
2) checked the color both ways RGB and BGR.
3) checked the initial bmp and final bmp (after applying flood fill).
4) checked floodfill with both signatures.
public void flood(int x,int y,int sourceColor,int newColor){
try {
Bitmap bmp;
if(OpenCVLoader.initDebug()){
image = new Mat();
mat1 = new Mat();
Utils.bitmapToMat(bmp2,mat1);
image = Mat.zeros(mat1.rows()+2,mat1.cols()+2,CvType.CV_8U);
if(bmp2.getWidth()==mat1.cols()){}
}
int k = mat1.channels();
int col = bmp2.getPixel(x, y);
int alpha = col & 0xFF000000;
int red = (col & 0x00FF0000) >> 16;
int green = (col & 0x0000FF00) >> 8;
int blue = (col & 0x000000FF);
double[] tt = (mat1.get(x,y));
Imgproc.cvtColor(mat1,mat1,Imgproc.COLOR_BGRA2BGR);
tt = (mat1.get(x,y));
//Imgproc.floodFill(mat1,image,p1,new Scalar(blue,green,red),new Rect(),new Scalar(230),new Scalar(220),4 + (255<<8) + Imgproc.FLOODFILL_MASK_ONLY);
Imgproc.floodFill(mat1,image,p1,new Scalar(255,255,255));
Core.subtract(image, Scalar.all(0), image);
Rect roi = new Rect(1, 1, mat1.cols() - 2, mat1.rows() - 2);
Mat temp = new Mat();
image.submat(roi).copyTo(temp);
mat1 = temp;
bmp = Bitmap.createBitmap(mat1.cols(),mat1.rows(),Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mat1,bmp);
}catch(CvException ex){
System.out.println(ex.getMessage());
ex.getLocalizedMessage();
}
}
↧