darknet icon indicating copy to clipboard operation
darknet copied to clipboard

Updated the code that allows to save the cropped image in result_img directory

Open shubham-shahh opened this issue 3 years ago • 19 comments

Bug Fix

  1. The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' and the code to save the image in result_img dir isn't updated based on the above conversion which was causing errors while recompiling the code. So, I've updated that, and now one can store the detected images in result_img dir. I've also updated the Readme.md based on that Fixes: #7276

Feature Addition

  1. I've added a new feature with which a user can run inference on all the images in the mentioned folder. I've also updated the readme with the information on how to use this feature.

shubham-shahh avatar Jan 24 '21 09:01 shubham-shahh

I have updated your initial message and reopened initial issue. The magic token "Fixes: #issue" will close the issue if/when this PR is merged automatically

cenit avatar Jan 24 '21 14:01 cenit

I have updated your initial message and reopened initial issue. The magic token "Fixes: #issue" will close the issue if/when this PR is merged automatically

okay, thanks :)

shubham-shahh avatar Jan 24 '21 14:01 shubham-shahh

@AlexeyAB what's your opinion on this PR? It fixes lines of code that are commented, as such they do not break nor fix anything. But, if the user was to uncomment those lines, they were broken and now ok

cenit avatar Jan 25 '21 14:01 cenit

  1. The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' and the code to save the image in result_img dir isn't updated based on the above conversion which was causing errors while recompiling the code. So, I've updated that, and now one can store the detected images in result_img dir. I've also updated the Readme.md based on that Fixes: #7276
  2. I've added a new feature with which a user can run inference on all the images in the mentioned folder. I've also updated the readme with the information on how to use this feature.

@cenit sir please review my recent changes, in which I've added this feature. Thanks.

shubham-shahh avatar Feb 07 '21 13:02 shubham-shahh

But why is ./darknet detector test ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights -i 0 -thresh 0.25 --folder_inference ./result_img/ better than darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < data/train.txt > result.txt ?

This < data/train.txt is more flexible, since you can put either all images from folder to the data/train.txt or only some images.

AlexeyAB avatar Feb 07 '21 15:02 AlexeyAB

But why is ./darknet detector test ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights -i 0 -thresh 0.25 --folder_inference ./result_img/ better than darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < data/train.txt > result.txt ?

This < data/train.txt is more flexible, since you can put either all images from folder to the data/train.txt or only some images.

Hello sir, I hope you are doing well. darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < data/train.txt > result.txt this command works well when the user knows the list of images in a folder and if no new images are added or subtracted from the folder because the program ends when the inference on all the images is done

./darknet detector test ./cfg/coco.data ./cfg/yolov4.cfg ./yolov4.weights -i 0 -thresh 0.25 --folder_inference ./result_img/ this command works well when new images are added constantly to a folder, as this program is non terminating and keeps looking for images in the folder. A common use case could be if new images are added to a folder from some other process and the user wants to do further inference on all the images in that folder. in this case new images are constantly added to the folder hence a user cannot make a list of it. one more example I can think of is if a user made an API to use their custom trained YOLO model, in that case, the images uploaded by the client can be stored in a folder on which the inference is done and the results are sent back

thanks for this awesome project @AlexeyAB

shubham-shahh avatar Feb 07 '21 17:02 shubham-shahh

I think it is not worth to complicate the code due to the functionality that is easily achieved by these functions.

  • Linux:

ls /home/user/*.jpg > filelist.txt

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt


  • Windows:

dir C:\images /b /s > "filelist.txt"

darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt

AlexeyAB avatar Feb 07 '21 20:02 AlexeyAB

I think it is not worth to complicate the code due to the functionality that is easily achieved by these functions.

  • Linux:

ls /home/user/*.jpg > filelist.txt

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt

  • Windows:

dir C:\images /b /s > "filelist.txt"

darknet.exe detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt

Sir, The procedure you mentioned is still terminating and the only way I can think of to make it non terminating is by creating a shell script that creates .txt files after every regular interval or to edit the code. In this approach, the user also has to make another .txt file to keep a track of images on which the inference has been done or delete the images or move them which again requires editing the code or putting that in a shell script. with this approach, ./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt has to be executed again and again which means the user has to load the model in GPU memory at regular intervals which is time-consuming and resource intensive. Regarding the complexity of code, I've added a simple if statement if the user wants to use this functionality this block of code will execute. and if the user doesn't use the functionality the code would execute the way it used to be.

shubham-shahh avatar Feb 07 '21 23:02 shubham-shahh

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt

NB!

rickkcir avatar Oct 17 '21 15:10 rickkcir

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt

NB!

What are you trying to say? Can you please clearly describe your issue?

shubham-shahh avatar Oct 17 '21 17:10 shubham-shahh

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt NB!

What are you trying to say? Can you please clearly describe your issue?

I want to get the coordinates,then I use this commad, but I found the file only saved relative coordinates,while I want to save the absolute coordinates, do you know how to realize it? thanks

rickkcir avatar Oct 18 '21 08:10 rickkcir

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.

// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);

pull request created for the same https://github.com/AlexeyAB/darknet/pull/8197

rg321 avatar Nov 02 '21 17:11 rg321

./darknet detector test cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output -dont_show -out result.json < filelist.txt > result.txt NB!

What are you trying to say? Can you please clearly describe your issue?

I want to get the coordinates,then I use this commad, but I found the file only saved relative coordinates,while I want to save the absolute coordinates, do you know how to realize it? thanks

You can get the absolute co ordinates since you already know the original image size

shubham-shahh avatar Nov 02 '21 17:11 shubham-shahh

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat.

// you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img);

pull request created for the same #8197

Can you clearly mention what exactly you're expecting?

Thanks

shubham-shahh avatar Nov 02 '21 17:11 shubham-shahh

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting?

Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

rg321 avatar Nov 16 '21 19:11 rg321

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting? Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting? Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

H

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting? Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, this PR also implements some more features along with solving that bug. That bug is simply solved by converting the image to ipltype, I tagged you where I have done that conversion. Rest changes of this PR are made to implement several other features

Thanks

shubham-shahh avatar Nov 17 '21 02:11 shubham-shahh

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting? Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting? Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

H

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting? Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, this PR also implements some more features along with solving that bug. That bug is simply solved by converting the image to ipltype, I tagged you where I have done that conversion. Rest changes of this PR are made to implement several other features

Thanks

In that case, you may either exactly mention in title of this pull request or you may want to create different pull request for the bug and a different one for features implemented. That would provide more clarity to your pull request. If possible, provide appropriate title to your pull request, what bug it solves or what feature it implements and add changes necessary for that only in that particular pull request. Else, as I mentioned above, for the problem mentioned in the title, my changes are good enough.

rg321 avatar Nov 24 '21 08:11 rg321

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting? Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting? Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

H

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting? Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

i

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting? Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting? Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

H

Hi, can you try following code in file src/image_opencv.cpp, show_img is Mat pointer. Just crop desired portion out of Mat. // you should create directory: result_img static int copied_frame_id = -1; // static IplImage* copy_img = NULL; if (copied_frame_id != frame_id) { copied_frame_id = frame_id; // if(copy_img == NULL) copy_img = cvCreateImage(cvSize(show_img->width, show_img->height), show_img->depth, show_img->nChannels); // cvCopy(show_img, copy_img, 0); } static int img_id = 0; img_id++; char image_name[1024]; sprintf(image_name, "result_img/img_%d_%d_%d_%s.jpg", frame_id, img_id, class_id, names[class_id]); CvRect rect = cvRect(pt1.x, pt1.y, pt2.x - pt1.x, pt2.y - pt1.y); cv::Mat copy_image = (*show_img)(rect); cv::imwrite(image_name, copy_image); // cvSetImageROI(copy_img, rect); // cvSaveImage(image_name, copy_img, 0); // cvResetImageROI(copy_img); pull request created for the same #8197

Can you clearly mention what exactly you're expecting? Thanks

@shubham-shahh as you mentioned at top of this page, you are trying to crop detections out of image. I just provided a simple way of doing that. As you pointed out, " The type of 'show_img' has been changed from 'iplimage' to 'cv::Mat' ", so just crop the detected area out of original image. For that I have just added following single line -: cv::Mat copy_image = (*show_img)(rect) rect is the rectange of detected object. We just crop that area from show_img and name it copy_image. Now save copy_image and it is cropped detectetion out of original image. To save copy_image, I use following code -: cv::imwrite(image_name, copy_image) Thats it, problem solved. You don't have to worry that " 'show_img' has been changed from 'iplimage' to 'cv::Mat' ".

Hi, this PR also implements some more features along with solving that bug. That bug is simply solved by converting the image to ipltype, I tagged you where I have done that conversion. Rest changes of this PR are made to implement several other features Thanks

In that case, you may either exactly mention in title of this pull request or you may want to create different pull request for the bug and a different one for features implemented. That would provide more clarity to your pull request. If possible, provide appropriate title to your pull request, what bug it solves or what feature it implements and add changes necessary for that only in that particular pull request. Else, as I mentioned above, for the problem mentioned in the title, my changes are good enough.

Hi, you can check the description, I have clearly mentioned what bug it solves and which feature it implements

thanks

shubham-shahh avatar Nov 24 '21 08:11 shubham-shahh

Hi @cenit looks like you've fixed the issue related to building in windows, can we merge this PR into master?

shubham-shahh avatar Oct 02 '23 02:10 shubham-shahh